Use method from other class like native methods?

The whole idea of instance methods, like xyz is in this, is that you are using the state of an instance of A in the method, without having to pass that instance as an argument like this:

... String xyz(A thisInstance, ...) {...}

Instead you use:

A thisInstance = ...;;

That’s why you need an instance of A, because it is practically an argument to the function.

However, if you don’t need an instance of A, you can make the method static:

static String xyz(...) {...}

Then you can call it without passing an instance of A:;

You can use a static import so that you don’t have to write A:

import static;



Leave a Comment