How to make ConstructorUtils.invokeConstructor work even when a value is stored in a string?
here is the code:
public static void main(String[] args) {
try {
String type = "java.lang.Character";
//char value = 'c'; //this work
String value = "c"; // this not work,throws[java.lang.NoSuchMethodException: No such accessible constructor on object: java.lang.Character]
Class<?> clazz = ClassUtils.getClass(type);
Object instance = ConstructorUtils.invokeConstructor(clazz, value);
System.out.println(instance);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException
| ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}