I want to create a method which takes a string argument and returns a class of that type.
For e.g. if I pass Long , it should return Long.class
psudo code:
private Class<?> classReturn(String className){
return new Class<className>;
}
Edit: : problem is I have values like "String" only. not "java.lang.String"
Edit2: I have a variable in String. I want to cast it to the above class.
For e.g.
String value=”1″;
String type= “Long”;
I want something like this (psudo code):
value = (classReturn(type)) value ;
You can use
if you have using a short class name you need to implement a path like
The closest you can do to convert strings is to assume some convention such as valueOf or a constructor which takes a String.
prints