Raymond,

You can get the type of T if you have a parameterized field of a generic
type. Some thing like this,

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;

public class Test<T> {
    
    private Test<String> myField;

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        
        Field field = Test.class.getDeclaredField("myField");
        ParameterizedType parameterizedType =
(ParameterizedType)field.getGenericType();
 
System.err.println(parameterizedType.getActualTypeArguments()[0]);
    }

}

Ta
Meeraj 

-----Original Message-----
From: Yang ZHONG [mailto:[EMAIL PROTECTED] 
Sent: 28 June 2006 01:19
To: tuscany-dev@ws.apache.org
Subject: Re: Question on java generics

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 <[EMAIL PROTECTED]> 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


This message has been checked for all email viruses by MessageLabs.



*****************************************************

    You can find us at www.voca.com

*****************************************************
This communication is confidential and intended for 
the exclusive use of the addressee only. You should 
not disclose its contents to any other person.
If you are not the intended recipient please notify 
the sender named above immediately.

Registered in England, No 1023742,
Registered Office: Voca Limited
Drake House, Three Rivers Court,
Homestead Road, Rickmansworth,
Hertfordshire, WD3 1FX


This message has been checked for all email viruses by MessageLabs.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to