Ultimately, I need to be able to do this in my code:
User result = goo.getEntity("users", "id1").getAs(User.class);
However, in the above code I need to explicitly cast the result of getEntity to User, what is the approach so that the return type of getAs will be whatever .class is put into the method.
Here is the underlying psuedo-code:
public class EntityType {
Map json = null;
public EntityType(Map json){
this.json = json;
}
public Class<?> getAs(Class<?> clazz){
// create clazz object from json map
}
}
public EntityType getEntity(String kind, String id){
Map json = getFromServer(kind, id);
EntityType entity = new EntityType(json);
return entity;
}
1 Answer