| Author |
Get a generic class' class?
|
Saverio Miroddi
Greenhorn
Joined: Jun 16, 2006
Posts: 21
|
|
I'd want to create a generic class, which I dould use the generic parameter in, both in a method return and to get the class' name. i haven't succeeded in accomplishing the 2nd. Suppose i have this: class SomeClass<C> { public C someMeth() { // this is OK } public void someOtherMeth() { ---> out.println(C.getSimpleName()); // this isn't possible! } } why isn't possible to call any C class method, even if C parameter it's supposed to be a real class?
|
Using a text editor for programming.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
|
Remember that calls to a static method are resolved when the calling code is compiled; when compiling a generic class, you don't know what that class is, so there's no way to check if it's a valid call. In any event, Java has no mechanism by which the "real" class could be substituted at runtime; remember that generics are a compile-time thing, and only one class is generated for the generic class, no matter how many times it is instantiated.
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: Get a generic class' class?
|
|
|