문제

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)

도움이 되었습니까?

해결책

Yes, use

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

다른 팁

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....

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top