Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8139324

13.4.9: Avoid use of Boolean constructor in example

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 9
    • 8
    • specification

      JLS 13.4.9 has the following:

      ==========
      We note, but do not recommend, that if a field of primitive type of an
      interface may change, its value may be expressed idiomatically as in:
          ...
          boolean debug = new Boolean(true).booleanValue();
          ...
      ==========

      This is not incorrect, but it uses the Boolean constructor, which is usually unnecessary and whose use is discouraged. I believe that all that's necessary here is to get a boolean value from an expression that's not a compile-time constant, so the following should be sufficient:

          boolean debug = Boolean.valueOf(true).booleanValue();

      Perhaps the JLS 13.4.9 example could be changed to use this instead.

            abuckley Alex Buckley
            smarks Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: