您的位置:程序门 -> java -> web 开发



请高手进来看看


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


请高手进来看看
发表于:2007-09-30 00:19:12 楼主
看了jdk还是不明白propertydescriptor在什么情况用instanceof对较   indexedpropertydescriptor类为true
请高手们讲解一下
发表于:2007-09-30 09:07:051楼 得分:0
人呢
发表于:2007-10-02 11:51:142楼 得分: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)   //这里为什么判断不相等   请高手讲一下
发表于:2007-10-02 12:32:243楼 得分:0
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明不明白?

发表于:2007-10-02 12:42:224楼 得分:0
接口a有两个实现类b和c:

b   b   =   new   b();
c   c   =   new   c();

b   instanceof   a       :   true
c   instanceof   a       :   true

b   instanceof   c       :   false   楼主问题的情况即是如此
c   instanceof   b       :   false   楼主问题的情况即是如此
发表于:2007-10-02 13:48:295楼 得分:0
谢谢楼上两位的解答   但是对indexedpropertydescriptor这个类的用法不是很懂   能举个例子说明一下么   再次谢谢。


快速检索

最新资讯
热门点击