Conversion from string to generic type
问题 I need to convert string to variable value. I found solution only for C#. I need it in Java. public class Property<T> { T value; public void setValue(String input){ if(value instanceof String){ value= input; // value is type of T not type of string (compilation error) // incompatible types: String cannot be converted to T } if(value instanceof int){ //parse string } if(value instanceof boolean){ //parse string } ... } } 回答1: That is not how it works. You can, however, use polymorphism, to