Frage

Can in java declare?

   (1) import static com.example.core.MyClass;

enter image description here

where:

public MyClass{
   public static double divide(){
      .....
   }
   public static double add(){
      .....
   }
}

and in the class where use static import to use freely: devide and add methods without the prefix - name of the class. From what I read we can do:

 import static com.example.core.MyClass.divide;
 import static com.example.core.MyClass.add;

But Can we do it in one statement as I mentioned in (1)

War es hilfreich?

Lösung

Yes, use

import static com.example.core.MyClass.*;

Andere Tipps

You can use import static com.example.core.MyClass.*;

MyClass.* will load all the properties inside the MyClass you won't need to access properties as MyClass.divide....

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top