Re: Reflecting generics
- From: Timbo <timbo@xxxxxxxxxxxxxxx>
- Date: Fri, 31 Mar 2006 15:35:11 +0100
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??
.
- Follow-Ups:
- Re: Reflecting generics
- From: Oliver Wong
- Re: Reflecting generics
- From: Dimitri Maziuk
- Re: Reflecting generics
- References:
- Reflecting generics
- From: Domagoj Klepac
- Reflecting generics
- Prev by Date: Re: Problems with using JFormattedTextField
- Next by Date: Re: volatile
- Previous by thread: Re: Reflecting generics
- Next by thread: Re: Reflecting generics
- Index(es):
Relevant Pages
|