A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© xiaodaodan 中级黑马   /  2015-5-19 22:45  /  6141 人查看  /  137 人回复  /   2 人收藏 转载请遵从CC协议 禁止商业使用本文

今天刚碰到的一个题.自我感觉 很霸气,绕过编译赋值,你敢信!!!
      看题  : ArrayList<Integer> list = new ArrayList<Integer>();在这个泛型为Integer的ArrayList中存放一个String类型的对象。
  1. public class Nb {
  2.         public static void main(String[] args) th<span style="line-height: 2.2em;">rows Exception {</span>
复制代码



点评

代码 怎么了?  发表于 2015-5-25 14:25

137 个回复

倒序浏览
我的代码怎么变成这个样子了!!!
回复 使用道具 举报
我重新发下代码吧,郁闷了...
public class Test2 {
        public static void main(String[] args) throws Exception {
                //创建ArrayList集合对象
                ArrayList<Integer> list = new ArrayList<Integer>();
                //使用集合对象调动getClass方法,获取字节码对象所对应的类,再获取集合的add方法
                Method methodAddString = list.getClass().getMethod("add", Object.class);
                //使用集合中的add方法对象,调用invoke方法,让集合对象使用add方法向集合中添加字符串元素
                methodAddString.invoke(list, "String类型");
                //输出集合中存入的字符串
                System.out.println(list);
        }
}

点评

最近也在学习  发表于 2015-5-20 16:59

评分

参与人数 1技术分 +1 收起 理由
lwj123 + 1

查看全部评分

回复 使用道具 举报
三军可夺帅也,匹夫不可夺其志也!!!

点评

强大  发表于 2015-5-25 14:26
回复 使用道具 举报
绕过编译?? 这段代码不用编译就能看到结果吗??  ctrl_F11 也不用按吗?
回复 使用道具 举报
反射的确很是强大
回复 使用道具 举报
rolan 中级黑马 2015-5-20 09:12:42
7#
赞一个,昨天也在弄这个
回复 使用道具 举报
不错,顶一个
回复 使用道具 举报
xiaodaodan 发表于 2015-5-19 22:52
我重新发下代码吧,郁闷了...
public class Test2 {
        public static void main(String[] args) throws Excep ...

如果要添加很多元素,就要调用很多次invoke吗?
回复 使用道具 举报
lizhi 来自手机 中级黑马 2015-5-20 09:25:06
10#
对呀,同时也很难学
回复 使用道具 举报
  学习了、
回复 使用道具 举报
受教了,我感觉就是反射仪这部分比较难,其他部分都学得差不多了
回复 使用道具 举报
有没有反射内容的资料呀
回复 使用道具 举报
确实要好好学习反射这部分内容啊
回复 使用道具 举报
xiaodaodan 发表于 2015-5-19 22:52
我重新发下代码吧,郁闷了...
public class Test2 {
        public static void main(String[] args) throws Excep ...

好吧   强大的程序能不能多给些金币
回复 使用道具 举报
表示还没有学到
回复 使用道具 举报
我在想,可以用在什么地放
回复 使用道具 举报
很好,很强大。。。。
回复 使用道具 举报
反射感觉好复杂  好麻烦的样子,比较喜欢网络编程,
回复 使用道具 举报
反射是很强大的
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马