javabean 属性名未知,现在要给这些属性设置默认值,以下是要求的默认值: 代码已经有了,就是提示错误帮忙 5
publicclassTestJavaBean{publicstaticvoidmain(String[]args)throwsException{JavaBeanj=n...
public class TestJavaBean {
public static void main(String[] args) throws Exception {
JavaBean j = new JavaBean();
Check(j);
PropertyDescriptor pd1 = new PropertyDescriptor("int", "int".getClass());//这而怎么设置int的属性值,不知道这里边怎么写了?
Method methodSetX = pd1.getWriteMethod();
methodSetX.invoke("int", 100); //这也是,怎么写
}
public static void Check(JavaBean j) throws IntrospectionException {
BeanInfo beaninfo = Introspector.getBeanInfo(j.getClass());
PropertyDescriptor[] pds = beaninfo.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) {
System.out.println(pd.getPropertyType() + "=" + pd.getName());
}
}
}
class JavaBean {//javaBean类
// 属性
private boolean b;
private int i;
private String s;
private double d;
public boolean isB() {
return b;
}
public void setB(boolean b) {
this.b = b;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public String getS() {
return s;
}
public void setS(String s) {
this.s = s;
}
public double getD() {
return d;
}
public void setD(double d) {
this.d = d;
}
public void show() {
System.out.println("boolean:" + isB() + ", " + "int:" + getI() + ", "
+ "String:" + getS() + ", " + "double:" + getD());
}
}
大侠们能不能看看怎么能让运行起来 展开
public static void main(String[] args) throws Exception {
JavaBean j = new JavaBean();
Check(j);
PropertyDescriptor pd1 = new PropertyDescriptor("int", "int".getClass());//这而怎么设置int的属性值,不知道这里边怎么写了?
Method methodSetX = pd1.getWriteMethod();
methodSetX.invoke("int", 100); //这也是,怎么写
}
public static void Check(JavaBean j) throws IntrospectionException {
BeanInfo beaninfo = Introspector.getBeanInfo(j.getClass());
PropertyDescriptor[] pds = beaninfo.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) {
System.out.println(pd.getPropertyType() + "=" + pd.getName());
}
}
}
class JavaBean {//javaBean类
// 属性
private boolean b;
private int i;
private String s;
private double d;
public boolean isB() {
return b;
}
public void setB(boolean b) {
this.b = b;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public String getS() {
return s;
}
public void setS(String s) {
this.s = s;
}
public double getD() {
return d;
}
public void setD(double d) {
this.d = d;
}
public void show() {
System.out.println("boolean:" + isB() + ", " + "int:" + getI() + ", "
+ "String:" + getS() + ", " + "double:" + getD());
}
}
大侠们能不能看看怎么能让运行起来 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询