Access static method on generic class-Collection of common programming errors
You can’t do that without reflection, because the type T
is erased at runtime (meaning it will be reduced to its lower bound, which is Base
).
Since you do have access to a Class
you can do it with reflection, however:
return (String) clazz.getMethod("getStaticName").invoke(null);
Note that I’d consider such code to be code smell and that it is pretty fragile. Could you tell us why you need that?