java报错误设置属性值_javabean 属性名未知,现在要给这些属性设置默认值,以下是要求的默认值: 代码已经有了,就是提示错误帮忙...

publicclassTestJavaBean{publicstaticvoidmain(String[]args)throwsException{JavaBeanj=newJavaBean();Check(j);PropertyDescriptorpd1=newPropertyDescriptor("int","int".getClas...

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());

}

}

大侠们能不能看看怎么能让运行起来

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值