本帖最后由 天方地圆 于 2014-4-5 22:03 编辑
- import java.lang.reflect.Method;
- import java.lang.reflect.ParameterizedType;
- import java.net.Proxy.Type;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Set;
- import java.util.Vector;
- public class GenericTest {
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception{
- // TODO Auto-generated method stub
- /*
- ArrayList<String> collection = new ArrayList<String>();
- collection.add("abc");
- String element = collection.get(0);
- System.out.println(element);
-
-
- ArrayList<Integer> collection2 = new ArrayList<Integer>();
- System.out.println(collection2.getClass() == collection.getClass() );
- collection2.getClass().getMethod("add", Object.class).invoke(collection2, "abc");
- System.out.println(collection2.get(0));
-
-
-
- HashMap<String,Integer> maps = new HashMap<String,Integer>();
- maps.put("anadgn", 30);
- maps.put("dsjgjdsg", 40);
- maps.put("abdg", 50);
-
- Set<Map.Entry<String,Integer>> entrySet = maps.entrySet();
- for(Map.Entry<String,Integer> entry : entrySet){
- System.out.println(entry.getKey() +":"+ entry.getValue());
- }
-
- swap(new String[]{"abc","bdg","itcast"},1,2);
- //swap(new int[]{1,23,4,5});
-
- Object obj = "abc";
- String x3 = autoConvert(obj);
- */
- //Vector<Date> v1 = new Vector<Date>();
- Method applyMethod = GenericTest.class.getMethod("applyMethod",Vector.class);
- java.lang.reflect.Type[] types = applyMethod.getGenericParameterTypes();
- ParameterizedType pType = (ParameterizedType)types(0);
- System.out.println(pType.getRawType());
- System.out.println(pType.getActualTypeArguments()[0]);
-
-
-
- }
- public static void applyMethod(Vector<Date> v1){
-
- }
- }
复制代码
|