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

Javac error when calling outer class method from method of same name from static inner class

XMLWordPrintable

    • x86_64
    • generic

      A DESCRIPTION OF THE PROBLEM :
      I have me strange behaviour of java compiler - seems to be a bug. Eclipse compiler compiles and program runs but javac does not compile. Program example is in `Steps to Reproduce` block.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      public class Test {
      public static void main(String[] args) {
      UpperLevelClass.InnerClass c = new UpperLevelClass.InnerClass();
      c.methodNameOne("a", new Integer(2));
      }
      }

      class UpperLevelClass {

      private static void methodNameTwo(String a, String b) {
      System.out.println("UpperLevelClass.methodNameTwo");
      }

      private static void methodNameOne(String a, String b) {
      System.out.println("UpperLevelClass.methodNameOne");
      }

      static class InnerClass extends UpperLevelClass {
      void methodNameOne(String a, Integer b) {
      System.out.println("InnerClass.methodNameOne");
      methodNameTwo("", "");
      methodNameOne("", "");//error
      }
      }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      InnerClass.methodNameOne
      UpperLevelClass.methodNameTwo
      UpperLevelClass.methodNameOne
      ACTUAL -
       error: incompatible types: String cannot be converted to Integer
            methodNameOne("", "");
                              ^
      Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
      1 error

      CUSTOMER SUBMITTED WORKAROUND :
      Specify upper level class name for static method. Like UpperLevelClass.methodNameOne.

      FREQUENCY : always


        1. Test.java
          0.7 kB
          Priyanka Mangal

            vromero Vicente Arturo Romero Zaldivar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: