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.

assylias
  • 321,522
  • 82
  • 660
  • 783
slackhacker
  • 523
  • 4
  • 8
  • 3
    Curious, but what's the purpose of importing a method to the file where it's implemented? – kiheru Jul 24 '13 at 13:54
  • @erencan Compile error man, what stacktrace? :S – m0skit0 Jul 24 '13 at 13:55
  • 4
    It could be related to [this similar bug](http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7177813). – assylias Jul 24 '13 at 13:55
  • Compiles fine in 1.7.0_21, both Eclipse and javac, without that redundant static import. – m0skit0 Jul 24 '13 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. – assylias Jul 24 '13 at 13:59
  • Compiles fine on 1.6.0_21-b07. Maybe author should clean/rebuild his project? =) – Alex Stybaev Jul 24 '13 at 14:00

1 Answers1

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
assylias
  • 321,522
  • 82
  • 660
  • 783