为什么' java.beans.PropertyEditorManager.findEditor(targetType)'的结果一片空白

时间:2017-09-05 13:37:53

标签: java reflection

我已经注册了" EntityEditor"," PropertyEditorManager.findEditor(...)"的结果应该是EntityEditor。但实际上结果是空的,我对此很困惑。有人可以帮忙吗?

我在MacOS-10上使用Oracle Java1.8。

import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.beans.PropertyEditorSupport;

.......
.......

@Test
public void test3() {
    PropertyEditorManager.registerEditor(Entity.class, EntityEditor.class);
    PropertyEditor editor = PropertyEditorManager.findEditor(Entity.class);
}

static class EntityEditor extends PropertyEditorSupport {
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        Entity entity = new Entity(text);
        setValue(entity);
    }
}

static class Entity {
    private String desc;

    public Entity(String desc) {
        this.desc = desc;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}

0 个答案:

没有答案