Re: Reflecting generics



On Fri, 31 Mar 2006 06:10:17 -0800, "Adam Maass"
<adam.nospam.maass@xxxxxxxxxxx> 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?

Generics are implemented by "type erasure." At runtime, any reference to
"java.lang.String" is long-since gone, so it can't be returned by any
reflective method.

Thought so. Adam, thanks for clarification.

Domchi
.



Relevant Pages

  • Re: Read what you type
    ... someone's acquaintance with scholarship while acknowledging that you don't know them from Adam. ... You're back to talking nonsense again Pete!! ... thought that somehow you had managed to unleash the forces of darkness upon him, I was dreading the knock in the night that would indicate the long reach of your mighty arm. ...
    (rec.sport.rugby.union)
  • Re: SP2 - longggggggg, slowwwww, shutdown
    ... my suspicion is that Prefetch is somehow involved, ... not sure why, how, or the fix. ... >adam wrote: ... >> SP2 seems to be running fine, but it is taking up to three ...
    (microsoft.public.windowsxp.general)
  • Re: Reflecting generics
    ... "Domagoj Klepac" wrote: ... Is it possible to, somehow, get "java.lang.String" from c? ... reflective method. ... -- Adam Maass ...
    (comp.lang.java.programmer)
  • Re: Monday Spilero
    ... Somehow I'd switched attention to Adam. ... Did his test tickle? ...
    (uk.media.radio.archers)
  • Re: Mindfulnessence a factor in Buddhas enlightenment?
    ... it was actually s'posed to be a bifurcation ... of a discombobulation but somehow it ... morphed into a clarification. ...
    (talk.religion.buddhism)