You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
have access to post topics
communicate privately with other members (PM)
not see advertisements between posts
have the possibility to earn one of our surprises if you are an active member
access many other special features that will be introduced later.
I have a mapping from variables to types. I am reading in those variables from a file as string and I need to convert them to their type dynamically. Since there are 100 or so varialbles, I don't want to code type conversion of each of them.
e.g. variable to type mapping:
public class Var {
public static Var v1 = new Var("double");
public static Var v2 = new Var("int");
public static Var v2 = new Var("String");
public Var(String type) {
_type = type;
}
public String getType() {
return _type;
}
}
Now I read in the variables from a file as strings. How do I dynamically convert them to their corresponding types?