You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Raymond Feng <en...@gmail.com> on 2006/06/28 02:08:16 UTC
Question on java generics
Generics gurus,
Assuming I have the following class:
public class Test<T> {
...
}
1) Is there a way to get the Class object for T in class Test? I know T.class is illegal.
2) Can I create the an instance of Test using a Class object myClass. I know new Test<myClass> is not valid.
Thanks,
Raymond
Re: Question on java generics
Posted by Yang ZHONG <le...@gmail.com>.
1) No. T is erasable.
2) If myClass is a class or generic type, you should be able to "new
Test<myClass>".
On the other hand, if myClass is a pointer/variable, no you can't "new
Test<myClass>"
On 6/27/06, Raymond Feng <en...@gmail.com> wrote:
>
> Generics gurus,
>
> Assuming I have the following class:
>
> public class Test<T> {
> ...
> }
>
> 1) Is there a way to get the Class object for T in class Test? I know
> T.class is illegal.
> 2) Can I create the an instance of Test using a Class object myClass. I
> know new Test<myClass> is not valid.
>
> Thanks,
> Raymond
>
>
>
--
Yang ZHONG