请高手进来看看 看了jdk还是不明白PropertyDescriptor在什么情况用instanceof对较 IndexedPropertyDescriptor类为true请高手们讲解一下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是这样的beanInfo=Introspector.getBeanInfo(beanClass);descriptors=beanInfo.getPropertyDescriptors();for (int i = 0; i < descriptors.length; i++){ if(descriptors[i] instanceof IndexedPropertyDescriptor) //这里为什么判断不相等 请高手讲一下 { ndexedPropertyDescriptor descriptor = (IndexedPropertyDescriptor)descriptors[i]; }}if(descriptors[i] instanceof IndexedPropertyDescriptor) //这里为什么判断不相等 请高手讲一下 descriptors=beanInfo.getPropertyDescriptors(); //这里返回的是PropertyDescriptor数组if(descriptors[i] instanceof IndexedPropertyDescriptor) //这里为什么判断不相等 请高手讲一下 { ndexedPropertyDescriptor descriptor = (IndexedPropertyDescriptor)descriptors[i]; //这里需要进行强制转换 } IndexedPropertyDescriptor是PropertyDescriptor的子类,一个对象是PropertyDescriptor的实例,但未必就一定是IndexedPropertyDescriptor的实例,反过来,一个对象是IndexedPropertyDescriptor的实例,就一定是PropertyDescriptor的实例。从代码上看,是要将descriptors数组的每个PropertyDescriptor对象进行强制转换,转换为IndexedPropertyDescriptor对象,如果不作判断,当某个PropertyDescriptor对象不是IndexedPropertyDescriptor的实例时就会出错,所以转换前进行类型判断。不知道这样说LZ明不明白? 接口A有两个实现类B和C:B b = new B();C c = new C();b instanceof A : truec instanceof A : trueb instanceof C : false 楼主问题的情况即是如此c instanceof B : false 楼主问题的情况即是如此 谢谢楼上两位的解答 但是对IndexedPropertyDescriptor这个类的用法不是很懂 能举个例子说明一下么 再次谢谢。 初学者问题,关于拦截器的param参数的作用。 关于jxl导出图片到xls 删除一个指定的Session 如何实现? 新手求教:怎样实现在表格单元格上单击弹出菜单,并记录当前单元格数值 用什么方法能获得 所有的 session对象??? 弱弱的问:Servlet和Bean的区别是什么啊? 怎样把字符串转换为Date格式? 这个错误提示是什么意思呀,怎么解决。。。 请问各位,怎样让新建的文件放在指定的目录里? 什么是rest?什么是ddd?请以用户管理模块为例,详细举例 jdbc2.0 想做一个统计工作天数的模块,碰到假日的问题
beanInfo=Introspector.getBeanInfo(beanClass);
descriptors=beanInfo.getPropertyDescriptors();for (int i = 0; i < descriptors.length; i++){
if(descriptors[i] instanceof IndexedPropertyDescriptor) //这里为什么判断不相等 请高手讲一下
{
ndexedPropertyDescriptor descriptor = (IndexedPropertyDescriptor)descriptors[i];
}
}if(descriptors[i] instanceof IndexedPropertyDescriptor) //这里为什么判断不相等 请高手讲一下
{
ndexedPropertyDescriptor descriptor = (IndexedPropertyDescriptor)descriptors[i]; //这里需要进行强制转换
} IndexedPropertyDescriptor是PropertyDescriptor的子类,一个对象是PropertyDescriptor的实例,但未必就一定是IndexedPropertyDescriptor的实例,反过来,一个对象是IndexedPropertyDescriptor的实例,就一定是PropertyDescriptor的实例。从代码上看,是要将descriptors数组的每个PropertyDescriptor对象进行强制转换,转换为IndexedPropertyDescriptor对象,如果不作判断,当某个PropertyDescriptor对象不是IndexedPropertyDescriptor的实例时就会出错,所以转换前进行类型判断。
不知道这样说LZ明不明白?
C c = new C();b instanceof A : true
c instanceof A : trueb instanceof C : false 楼主问题的情况即是如此
c instanceof B : false 楼主问题的情况即是如此