I have a question, I want to import a class, and when I have imported the class. I don't want to have to re-call the imported class. For example, instead of Class.method();. It will just simply be method();.
Asked
Active
Viewed 50 times
-5
-
1You could try extending that class – Logan Jul 06 '16 at 06:52
-
Can you elaborate on what you mean by "calling" or "re-calling" a class? Classes aren't called. Are you referring to methods or constructors? – Ray Toal Jul 06 '16 at 06:52
-
This isn't good code style for OOP – CloudPotato Jul 06 '16 at 06:54
-
@Blobonat Agreed! What's the problem by calling `Class.method()`? – antoniodvr Jul 06 '16 at 07:05
1 Answers
3
You can so this with import static
if method()
is a static
method:
import static com.somepackage.SomeClass.method;
// ...
// Will call SomeClass.method();
method();
This obviously won't work with non-static methods, because you have to specify on which object you want to call the non-static method.

Jesper
- 202,709
- 46
- 318
- 350