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

A bug in javac that prevents variable shadowing

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.1
    • tools
    • generic
    • generic



      Name: skT88420 Date: 08/16/99


      // Platform: Windows 98
      // java version "1.2.1"
      // Classic VM (build JDK-1.2.1-A, native threads)

      /*
      Bug: When I compile this source file the "javac" compiler gives me an error
      that the variable 'f' is already defined in this method (Line 21) when I
      think it shouldn't do that (variable shadowing! and 'f' in main() is not
      final so anonymous classes can't access it anyway!). To be sure about that,
      I recompiled this source file using Microsoft's "JVC" compiler and it didn't
      generate any errors. And the 'java' VM was able to interpret it.
      */

      public class CompilerBug {

          public static void main(String[] Args) {
          int f = 10;

              (new Test() {
                  public void test(int z) {
                  int f = 50; // Variable 'f' is already defined in this method!!!?

                      System.out.println(z + f);
                  }
              }).test(f);

          }

      }

      interface Test {
          public void test(int z);
      }
      (Review ID: 93838)
      ======================================================================

            iris Iris Clark
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: