下面的代码很简单,编译也没有问题,但是执行报错,小弟我能力有限,发现不了原因,请各位大大帮忙,多谢!//----------------------------------
import java.beans.Introspector;public class TestIndexProperty extends Base { public static void main(String[] args) throws Throwable {
Introspector.getBeanInfo(TestIndexProperty.class);
} public Integer[] getProp() {
return null;
} public Integer getProp(int i) {
return null;
}}class Base {
public Number[] getProp() {
return null;
} public Number getProp(int i) {
return null;
}
}
//----------------------------------
异常如下:
Exception in thread "main" java.lang.AssertionError: java.beans.IntrospectionException: type mismatch between indexed and non-indexed methods: prop
at java.beans.IndexedPropertyDescriptor.<init>(IndexedPropertyDescriptor.java:425)
at java.beans.Introspector.processPropertyDescriptors(Introspector.java:674)
at java.beans.Introspector.getTargetPropertyInfo(Introspector.java:612)
at java.beans.Introspector.getBeanInfo(Introspector.java:404)
at java.beans.Introspector.getBeanInfo(Introspector.java:168)
at TestIndexProperty.main(TestIndexProperty.java:6)
Caused by: java.beans.IntrospectionException: type mismatch between indexed and non-indexed methods: prop
at java.beans.IndexedPropertyDescriptor.findIndexedPropertyType(IndexedPropertyDescriptor.java:341)
at java.beans.IndexedPropertyDescriptor.setIndexedReadMethod(IndexedPropertyDescriptor.java:177)
at java.beans.IndexedPropertyDescriptor.<init>(IndexedPropertyDescriptor.java:416)
... 5 more
import java.beans.Introspector;public class TestIndexProperty extends Base { public static void main(String[] args) throws Throwable {
Introspector.getBeanInfo(TestIndexProperty.class);
} public Integer[] getProp() {
return null;
} public Integer getProp(int i) {
return null;
}}class Base {
public Number[] getProp() {
return null;
} public Number getProp(int i) {
return null;
}
}
//----------------------------------
异常如下:
Exception in thread "main" java.lang.AssertionError: java.beans.IntrospectionException: type mismatch between indexed and non-indexed methods: prop
at java.beans.IndexedPropertyDescriptor.<init>(IndexedPropertyDescriptor.java:425)
at java.beans.Introspector.processPropertyDescriptors(Introspector.java:674)
at java.beans.Introspector.getTargetPropertyInfo(Introspector.java:612)
at java.beans.Introspector.getBeanInfo(Introspector.java:404)
at java.beans.Introspector.getBeanInfo(Introspector.java:168)
at TestIndexProperty.main(TestIndexProperty.java:6)
Caused by: java.beans.IntrospectionException: type mismatch between indexed and non-indexed methods: prop
at java.beans.IndexedPropertyDescriptor.findIndexedPropertyType(IndexedPropertyDescriptor.java:341)
at java.beans.IndexedPropertyDescriptor.setIndexedReadMethod(IndexedPropertyDescriptor.java:177)
at java.beans.IndexedPropertyDescriptor.<init>(IndexedPropertyDescriptor.java:416)
... 5 more
import java.beans.Introspector;public class TestIndexProperty extends Base { public static void main(String[] args) throws Throwable {
Introspector.getBeanInfo(TestIndexProperty.class);
} public Integer[] getProp() {
return null;
} public Integer[] getProp(int i) {
return null;
}}class Base {
public Number[] getProp() {
return null;
} public Number[] getProp(int i) {
return null;
}}bean的类型不匹配。
一个用Number[] , 一个用Number;但这两个是同一个bean属性 prop
所以匹配不上
我觉得在代码编写上应该是没有什么问题的,而且也会存在这种场景,只是jdk的处理可能有bug
是Number 与 Number[]的问题; 这是两个完全不同的类型。后一个是数组
Introspector.getBeanInfo(TestIndexProperty.class);
} public Integer[] getProp() {
return null;
} public Integer getProp(int i) {
return null;
}}