I have some functions collected as methods in a class called func. I use those methods quite often in different classes. Is there a way in java to call those functions without creating a new object or calling it like this: func.myFunction();?
I want: myFunction();
There are two issues:
The first one is easy to solve: if your method doesn’t actually use any non-static members (fields or methods) of the class, then simply adding the
statickeyword enables you to call it without an instance of the class:And about the second item: I kind-of lied there, you can do that, but you need a static import:
Also: there are no functions in Java, only methods.