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

Request for extra compiler warnings

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 1.1
    • tools
    • None
    • sparc
    • solaris_2.5



      Name: sgC58550 Date: 03/25/97


      The following program compiles without warnings:

      public class warn {
          public static void main(String argv[]) {
              new warn();
              String s;
              boolean a = false, b = true;
              if (a = b)
                  s = "Goodbye, cruel world!";
              else
                  s = "Hello, world!";
              System.out.println(s);
          }
       
          public void warn() {
              System.out.println("Constructor");
          }
      }

      However, the assignment of b to a inside the if conditional and
      the declaration of a method that has a return type and the same
      name as the class (making it look like it's a constructor when
      it's not) will very often be not what the programmer meant.

      I'm used to compilers such as g++ that give warnings on many
      suspect contructions such as the two above, and allow the
      user to selectively turn on and off these various warnings.
      I'd like to be able to provide javac with command-line options
      so that the above code will generate two warnings, or compile
      with no warnings, depending on what warnings I'm interested in.
      company - UCSB , email - ###@###.###
      ======================================================================

            dstoutamsunw David Stoutamire (Inactive)
            sgoodsunw Sheri Good (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: