There is a variable (values) in class1 (package1), you need to import it into class2 (package2).

There are 2 ways:

package package2; import package1.class1; 

or go straight to the variable

 package package2; package1.class1.values... 

Which way is faster in terms of performance?

PS Usability does not care!

  • 3
    Equally. Can direct appeal for a split second faster compiled. - pavel

1 answer 1

It will not affect the speed of the program, because the compiler will anyway replace the name of the variables with full paths. For example,

 package aug; import static java.lang.System.out; public class MyClass { public static void main(String[] args) { out.println("abc"); } } 

If you look at the decompiler:

 package aug; public class MyClass { public MyClass() { } public static void main(String[] args) { System.out.println("abc"); } } 

Part of bytecode:

  public static main([Ljava/lang/String;)V L0 LINENUMBER 7 L0 GETSTATIC java/lang/System.out : Ljava/io/PrintStream; LDC "abc" INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V L1 LINENUMBER 8 L1 RETURN L2 LOCALVARIABLE args [Ljava/lang/String; L0 L2 0 MAXSTACK = 2 MAXLOCALS = 1 }