请写出如下代码的运行结果(22)

tteesstt 2008-07-07 10:11:06
加精
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class T {
public static synchronized void main(String[] a) throws Exception {
T t = new T();
Method m = t.getClass().getMethod("hasNext");
System.out.print(m.invoke(t));
List<T> list = new ArrayList<T>();
list.add(t);
Iterator it = list.iterator();
m = it.getClass().getMethod("hasNext");
System.out.print(m.invoke(it));
}

public boolean hasNext() {
return true;
}
}
...全文
6037 137 打赏 收藏 转发到动态 举报
写回复
用AI写文章
137 条回复
切换为时间正序
请发表友善的回复…
发表回复
满脑子灵感 2012-10-24
  • 打赏
  • 举报
回复
trueException in thread "main" java.lang.IllegalAccessException: Class cn.myeee.java.T can not access a member of class java.util.AbstractList$Itr with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.reflect.Method.invoke(Method.java:588)
at cn.myeee.java.T.main(T.java:17)
GarwayWong 2012-09-20
  • 打赏
  • 举报
回复
广州 招聘
熟悉OSS,SQL UNIX Java Development Oracel XML, HTML, SVG
要求本科,熟悉英文方面的專業用語(因為該公司是外資企業,也是世界前五百強.面試也是外國人面的)3年工作经验
月薪大概10K到12K
JavaScript_R 2012-09-20
  • 打赏
  • 举报
回复
比我还无聊
JavaScript_R 2012-09-20
  • 打赏
  • 举报
回复
没意思
albertwmm 2012-09-08
  • 打赏
  • 举报
回复
MAKE
小飞侠168 2012-08-30
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]
引用 3 楼 bestaone 的回复:
trueException in thread "main" java.lang.IllegalAccessException: Class T can not access a member of class java.util.AbstractList$Itr with modifiers "public"
System.out.print(m.i……
[/Quote]

赞同
profk 2012-07-25
  • 打赏
  • 举报
回复
好高深,学习学习
Nes_Man 2012-03-30
  • 打赏
  • 举报
回复
虽然不知道是什么 但是感觉很厉害的样子 学习~
nj2012 2012-02-09
  • 打赏
  • 举报
回复
看不懂,我要疯了。。。
chc464954573 2012-01-17
  • 打赏
  • 举报
回复
学习!
java_freshman01 2012-01-15
  • 打赏
  • 举报
回复

public class T {
public static synchronized void main(String[] a) throws Exception {
T t = new T();
Method m = t.getClass().getMethod("hasNext");
System.out.println(m.invoke(t));
List<T> list = new ArrayList<T>();
list.add(t);
//Iterator it = list.iterator();//为什么要这样做?
for(T it : list){
m = it.getClass().getMethod("hasNext");
System.out.print(m.invoke(it));
}
}

public boolean hasNext() {
return true;
}
}

superliandi 2012-01-06
  • 打赏
  • 举报
回复
本人菜鸟,搞不懂
Jaya1989 2011-12-25
  • 打赏
  • 举报
回复
m.setAccessible(true);
windyvov 2011-11-01
  • 打赏
  • 举报
回复
<b>学习了</b>
y_0715 2011-09-20
  • 打赏
  • 举报
回复
顶。。。。。。。。。
ojwftded 2011-09-08
  • 打赏
  • 举报
回复
实例中的it声明成了迭代器,当然调不到他的hasNext方法了
如果你把代码改成这样
T t2 = it.next();
m = t2.getClass().getMethod("hasNext");

或者这样
for(T t3 : list){
m = t3.getClass().getMethod("hasNext");
System.out.println(m.invoke(t3));
}
呢?
q451379521 2011-08-21
  • 打赏
  • 举报
回复
不懂,高深额
yarmee 2011-08-15
  • 打赏
  • 举报
回复
????????????????????????
你好毒你好毒 2011-08-15
  • 打赏
  • 举报
回复
我的修改:
public static synchronized void main(String[] a) throws Exception {
Test t = new Test();
Object obj = t.getClass().newInstance();
Method m = t.getClass().getMethod("hasNext");
System.out.print(m.invoke(obj));
List<Test> list = new ArrayList<Test>();
list.add(t);
Iterator it = list.iterator();
m = it.next().getClass().getMethod("hasNext");
System.out.print(m.invoke(obj));
}

public boolean hasNext() {
return true;
}
wang_huanming 2011-04-27
  • 打赏
  • 举报
回复
结果报错啊
加载更多回复(113)

62,617

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧