public class ds
{
private String name;
private String age;
private String sex;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getAge()
{
return age;
}
public void setAge(String age)
{
this.age = age;
}
public String getSex()
{
return sex;
}
public void setSex(String sex)
{
this.sex = sex;
}
}
package matck.ma;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class invort
{
/**
* <[Description]>
* @param args
* @author yKF51945
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
{
ds sc = new ds();
sc.setName("hello");
sc.setAge("18");
sc.setSex("man");
vort(sc);
}
public static void vort(ds sc) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
{
String filed ="";
Class<?> beanclass = sc.getClass();
Method[] methods = beanclass.getMethods();
for(Method md :methods)
{
if( md.getName().equals("getName"))
{
filed = (String) md.invoke(sc);
if("hello".equals(filed))
{
System.out.println(filed);
}
}
}
}
}