Is it possible to return in a static method a class? I will explain…
I have:
public class A { public static void blah(){} }
public class B { }
I want to create a static method in B witch returns A. So you can do:
A.blah();
And
B.getA().blah();
This, without creating an instance of A. Just use it static methods.
Is this possible?
This is a rebuttal of @irreputable’s answer:
It “works”, but probably not in the sense that you expect, and certainly not in a useful way. Let’s break this down into two parts:
The first statement is returning a (null in this case) instance of
A, and the second statement is ignoring that instance and callingA.blah(). So, these statements are actually equivalent toor (given that
getA()is side-effect free), just plainAnd here’s an example which illustrates this more clearly:
… and this (I hope) illustrates why this approach doesn’t solve the OP’s problem.