}
}
我在上班看毕老师笔记偷偷敲的,反射这块感觉很疑惑,求教一下,怎么学习理解它
执行getMethodDemo1() 没问题
结果
public static void com.itheima.bean.Person.Show()
public void com.itheima.bean.Person.setAge(int)
public int com.itheima.bean.Person.getAge()
public java.lang.String com.itheima.bean.Person.getName()
public void com.itheima.bean.Person.setName(java.lang.String)
public static void com.itheima.bean.Person.main(java.lang.String[])
但是执行 getMethodDemo2()、getMethodDemo3()
都报错:
Exception in thread "main" java.lang.NoSuchMethodException: com.itheima.bean.Person.show()
at java.lang.Class.getMethod(Class.java:1624)
at com.itheima.reflect.demo.ReflectDemo4.getMethodDemo2(ReflectDemo4.java:34)
at com.itheima.reflect.demo.ReflectDemo4.main(ReflectDemo4.java:16) 作者: 王松松 时间: 2014-4-29 20:55
你的Person类中找不到show( )方法作者: 占琳 时间: 2014-4-29 22:39
那么明显你的类当中没有show方法作者: 大漠孤烟 时间: 2014-4-30 23:21
package com.itheima.bean;
public class Person {
/**
* @param args
*/
private String name;//姓名
private int age; //年龄
public static void main(String[] args) {
// TODO Auto-generated method stub
Person p=new Person();
p.setName("小米");
p.setAge(22);
System.out.print("这个人的姓名"+p.getName()+"年龄"+p.getAge());
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Person(){
System.out.print("人出生就会哭");
}
public Person(String name,int age){
System.out.print("这个人的姓名"+this.name+"年龄"+this.age);
}
public static void show(){
System.out.print("展示才艺");
}