Forum Stats

  • 3,826,609 Users
  • 2,260,677 Discussions
  • 7,897,029 Comments

Discussions

How can I import static members from another class?

I'm trying to import static members from another class. The code examples below are in separate .java files. TestStaticClassMember is compiled first using:

javac TestStaticClassMember.java

followed by:

javac TestClass.java

TestStaticClassMember is not a recognised symbol to TestClass using the import construct:

import static TestStaticClassMembers.*;

featured within the examples below. Why is that?

public class TestStaticClassMember {

  public static double getDate(double in)

  {

     return in;

  }

}

import static TestStaticClassMember.*;

public class TestClass{

}

I've tried to recreate the compile error from the class RandomUtil.java (which has static members) and Branch.java that wants to use those static members from RandomUtil.

These classes are in the tree package from tree_animation found in the Oracle documentation.