Есть ли способ указать имя строки свойства в конкретном компоненте и вернуть класс, который соответствует получателю?Java Reflection Property String name -> Class Datatype
1
A
ответ
3
Вы можете использовать класс java.beans.Introspector для получения информации о данном компоненте. Вы не можете запросить BeanInfo для конкретного собственности, но вы можете цикл через них:
private Class<?> getPropertyType(Class<?> clazz, String property) {
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
PropertyDescriptor[] propDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor propDescriptor : propDescriptors) {
// String name of a property
if (property.equals(propDescriptor.getName())) {
// Class the getter corresponds to.
return propDescriptor.getPropertyType();
}
}
...
}
0
находит ... org.apache.commons.beanutils.PropertyUtils.getPropertyType (боб Object, String, имя)
Смежные вопросы
- 1. Java - Reflection Extract Class
- 2. Java Class Property
- 3. java public class name <Item>
- 4. C++ String to class name
- 5. linq orderby using property name string
- 6. типов аргументов посланных getDeclaredMethod (String, Class []) в Java Reflection
- 7. Java getName (String name)
- 8. Java - String Class, Scanner Class
- 9. String -> Объект с использованием Reflection?
- 10. Список <string> name to string
- 11. Java Array Name From String
- 12. Java Reflection getDeclaredMethod() с Generic Class Тип
- 13. OrderBy on List <string> property
- 14. HashMap <String, Class>
- 15. ant machine name property
- 16. MVC routes.MapRoute name property
- 17. Call Class from String - Java
- 18. Portable Class Library Reflection
- 19. find class Name
- 20. Что означает <property name = "hibernate.setup"> true</property> in Confluence do?
- 21. Iterator.class против итератора <String> .class
- 22. элемент [class = "name"] вместо .class
- 23. Portable Class Library Reflection GetField
- 24. Reflection - читать свойство типа class, а не string или int
- 25. Reflection API, Class.forName() против .class
- 26. Метод Class in Reflection API
- 27. API Java Reflection - получение значения поля String []
- 28. Сложное поведение java.beans.PropertyDescriptor (String, Class)
- 29. Lazy class property decorator
- 30. iOS get property class
Знаете ли вы, может ли BeanUtil это сделать? –
Я так думаю, но вы, вероятно, должны заявить, что используете Apache Commons, прежде чем задавать вопрос! –