反射如何越过泛型检查

 

 

 

 

 

package com.mayikt.test;

import com.mayikt.entity.UserEntity;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

/**
 * @author 余胜军
 * @ClassName Test05
 * @qq 644064779
 * @addres www.mayikt.com
 * 微信:yushengjun644
 */
public class Test05 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
//        ArrayList<String> arrayList = new ArrayList<>();
//        arrayList.add("mayikt");
////        strings.add(111);
//        Class<? extends ArrayList> aClass = arrayList.getClass();
//        Method addMethod = aClass.getDeclaredMethod("add", Object.class);
//        addMethod.invoke(arrayList, 1);
//        System.out.println(arrayList);
//        arrayList.forEach((t) -> {
//            System.out.println(t);
//        });

    }
}

 

posted @ 2021-11-25 13:07  AngDH  阅读(26)  评论(0编辑  收藏  举报