I have a class:
class Superclass { static List list() { ... } }
and subclasses:
class Subclass extends Superclass { ... }
class Subclass2 extends Superclass { ... }
I want to call the list
method like this: Subclass.list()
or Subclass2.list()
, and do something different based on which subclass it was called with.
Is there a way I can tell which subclass is calling the list
method?
Note: I don't want to have to override the list
method in each of the subclasses.
UPDATE: Everyone is saying this is bad design, and in most cases I think it would be, but I don't think so in my case. My ORM defines methods that take in a java.lang.Class
. I want to provide a shorthand for my ORM's methods so that I can say User.list(...)
instead of ORM.list(User.class, ...)
.