import java.lang.reflect.InvocationTargetException;
import org.apache.commons.beanutils.BeanUtils;
public class Test
{
public static void main(String[] args)
{
try
{
String echoVal = "";
//
//InsidePack insidePack = new InsidePack();
//BeanUtils.setProperty(insidePack, "x", 12);//异常
//echoVal = BeanUtils.getProperty(insidePack, "x");//异常
//System.out.println("InsidePack" + echoVal);
//
//PriSubClass priSubClass = new PriSubClass();
//BeanUtils.setProperty(priSubClass, "x", 24);//异常
//echoVal = BeanUtils.getProperty(priSubClass, "x");//异常
//System.out.println("PriSubClass" + echoVal);
//
//ProSubClass proSubClass = new ProSubClass();
//BeanUtils.setProperty(proSubClass, "x", 36);//异常
//echoVal = BeanUtils.getProperty(proSubClass, "x");//异常
//System.out.println("ProSubClass" + echoVal);
//
PubSubClass pubSubClass = new PubSubClass();
BeanUtils.setProperty(pubSubClass, "x", 48);
echoVal = BeanUtils.getProperty(pubSubClass, "x");
System.out.println("PubSubClass" + echoVal);
//
Outer outer = new Outer();
BeanUtils.setProperty(outer, "x", 60);
echoVal = BeanUtils.getProperty(outer, "x");
System.out.println("Outer" + echoVal);
//
//OutPack outPack = new OutPack();
//BeanUtils.setProperty(outPack, "x", 72);//异常
//echoVal = BeanUtils.getProperty(outPack, "x");//异常
//System.out.println("OutPack" + echoVal);
}
catch(IllegalAccessException e)
{
e.printStackTrace();
}
catch(InvocationTargetException e)
{
e.printStackTrace();
}
catch(NoSuchMethodException e)
{
e.printStackTrace();
}
}
private static class PriSubClass
{
private int x;
public int getX()
{
return x;
}
public void setX(int x)
{
this.x = x;
}
}
protected static class ProSubClass
{
private int x;
public int getX()
{
return x;
}
public void setX(int x)
{
this.x = x;
}
}
public static class PubSubClass
{
private int x;
public int getX()
{
return x;
}
public void setX(int x)
{
this.x = x;
}
}
}
class InsidePack
{
private int x;
public int getX()
{
return x;
}
public void setX(int x)
{
this.x = x;
}
}
使用BeanUtils操作属性的一个小坑
需积分: 50 155 浏览量
2013-02-03
13:53:15
上传
评论
收藏 1KB ZIP 举报
小卖部书记
- 粉丝: 1
- 资源: 34
最新资源
- tensorflow-2.7.3-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.7.2-cp39-cp39-manylinux2010-x86-64.whl
- Python版本快速排序源代码
- Python 语言版的快速排序算法实现
- 450815388207377安卓_base.apk
- 超微主板 X9DRE-TF+ bios 支持 nvme启动
- 基于Python通过下载气象数据和插值拟合离散数据曲线实现对寒潮过程的能量分析
- 健身房系统的设计与实现论文Java项目
- 使用TCP实现的搜索可用服务器
- 使用贪心算法解决会议时间安排问题的 Java 示例代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈