-5

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();.

MightyDanp
  • 21
  • 1
  • 3

1 Answers1

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