7

This compiles fine in Eclipse JDT but not on 1.6.30 or 1.7.25:

package doh;

import static doh.Wtf.InnerClass.innerclassMethod;
import java.io.Serializable;

public class Wtf {

    static class InnerClass implements Serializable {   
        public static void innerclassMethod() {            
        }
    }
}

With javac I get the following compile error:

error: cannot find symbol
  static class InnerClass implements Serializable {     
symbol:   class Serializable
location: class Wtf

Commenting out the superfluous static import makes the code compile. So does reordering the import statements.

6
  • 3
    Curious, but what's the purpose of importing a method to the file where it's implemented? Commented Jul 24, 2013 at 13:54
  • @erencan Compile error man, what stacktrace? :S Commented Jul 24, 2013 at 13:55
  • 4
    It could be related to this similar bug. Commented Jul 24, 2013 at 13:55
  • Compiles fine in 1.7.0_21, both Eclipse and javac, without that redundant static import. Commented Jul 24, 2013 at 13:57
  • 1
    @kiheru Without the static import, you would have to call the method: InnerClass.innerClassMethod();. With the static import, you can just use innerClassMethod();. So same reason as with any other static import statement. Commented Jul 24, 2013 at 13:59

1 Answer 1

8

I get the same compile error with jdk 1.7.25.

It seems to be a known bug (although the example given in the bug report uses an enum as the nested class but it is conceptually identical) and the proposed workarounds are the same as those you describe:

  • swap import statements
  • remove static import and use fully qualified name
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.