0
我有一个方法,它返回一般数据的向量。如何在运行时获取此Vector矢量儿童的类型?我花了一天的时间试图在Java文档和谷歌中找到解决方案。 当我尝试做即:强类型数组的泛型向量
Vector<String> myVector = new Vector<String>();
//here I fill array with data
.......
// here I my code don't know now what is element type of
// myVector and need to get it in some way
Class<?> baseClass = myVector.toArray().getClass().getComponentType();
最后一行返回我Object
。
是它的'VECTOR'不会是空的情况? – hmjd 2012-03-01 11:12:22