Re: Reflecting generics
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Fri, 31 Mar 2006 17:39:26 GMT
"Timbo" <timbo@xxxxxxxxxxxxxxx> wrote in message news:e0jr7q$ebd$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Domagoj Klepac wrote:I'm wondering if this is possible - and after much digging, it seems
that it isn't. I have the following piece of code:
ArrayList<String> stringArray = new ArrayList<String>();
Class c = stringArray.getClass();
Is it possible to, somehow, get "java.lang.String" from c?
Or is that information lost after compiling?
Domchi
Hmm... it appears that you can't. I would have thought that you could do the following:
Class<? extends ArrayList<String>> c = stringArray.getClass();
which would at least give you the compile-time type, but my compiler is complaining that the assignment:
Test.java:8: incompatible types
found : java.lang.Class<capture of ? extends java.util.ArrayList>
required: java.lang.Class<? extends java.util.ArrayList<java.lang.String>>
Class<? extends ArrayList<String>> c = stringArray.getClass();
^
Am I missing something here??
The following code:
<code>
import java.util.ArrayList;
public class FillTest {
public static void main(String args[]) {
ArrayList<String> stringArray = new ArrayList<String>();
Class<? extends ArrayList<String>> c = stringArray.getClass();
}
}
</code>
Compiles fine for me on Eclipse 3.2M5.
- Oliver
.
- References:
- Reflecting generics
- From: Domagoj Klepac
- Re: Reflecting generics
- From: Timbo
- Reflecting generics
- Prev by Date: Re: Merging two or more pictures into one?
- Next by Date: Re: Java 1.6
- Previous by thread: Re: Reflecting generics
- Next by thread: Re: Reflecting generics
- Index(es):
Relevant Pages
|