Choice of class handled inconsistently with javac/java and java

XMLWordPrintable

    • Type: Bug
    • Resolution: Not an Issue
    • Priority: P3
    • None
    • Affects Version/s: 11, 17, 21
    • Component/s: tools
    • b26
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      This is with JDK 21 build 26. Consider this file named HelloWorld.java:

      class Base {
         public static void main() {
            System.out.println("Hello, World1!");
         }
      }

      class HelloWorld extends Base {
         public void main(String[] args) {
            System.out.println("Hello, World2!");
         }
      }


      Now consider the outputs of

      javac --enable-preview --source 21 HelloWorld.java
      java --enable-preview HelloWorld
      # Prints Hello, World2!

      and

      java --enable-preview --source 21 HelloWorld.java
      # Prints Hello, World1!



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See above

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I believe it should print Hello, World1! in both cases
      ACTUAL -
      See above

      ---------- BEGIN SOURCE ----------
      See above
      ---------- END SOURCE ----------

            Assignee:
            Christian Stein
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: