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

Choice of class handled inconsistently with javac/java and java

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 11, 17, 21
    • 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 ----------

            cstein Christian Stein
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: