Can this be done in Java
public <T> T[] getAttr(String s) {
Object x = getSomething(s);
com.class."s"[] y = (com.class."s"[]) x;
return y;
}
I realise this is all very rough. But the basic principle can this be achieved in Java.
EDIT:
Guys I already have the object I wish return x. I just want it returned as the correct type. I.e the class version of s
get the class
create an array of the specified runtime type and length:
You are going to have to suppress some warnings about type-safety. There is no way around that if you really want to go from Strings. Maybe pass in a Class object instead, then it can be made type-safe.