public class Test<T>{
//...........
}////////////////////如何在Test里面获取T的类型?
比如当 Test<String> test=new Test<String>()
Test里面如何获取T就的String??
能不能获得?如何获得?
//...........
}////////////////////如何在Test里面获取T的类型?
比如当 Test<String> test=new Test<String>()
Test里面如何获取T就的String??
能不能获得?如何获得?
看看这帖
http://topic.csdn.net/u/20090301/23/0d71ecc8-221b-483b-9623-c549784f657d.html
在java中,泛型类型只有在静态类型检查期间才出现,在此之后,程序中的所有泛型类型都将被擦出,替换为它们的非泛型上界。例如List<T>这样的类型注解将被擦除为List,而普通的类型变量在未指定边界的情况下将被擦出为Object。
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace ConsoleApplication1
{
class Test<T>
{
public Type GetType()
{
return typeof(T);
}
}
class Program
{
static void Main(string[] args)
{
Test<String> test = new Test<string>();
Type type = test.GetType();
Console.WriteLine(type.FullName);
}
}
}