V
visionset
I thought it might be possible to have just one getter for a variety of
Object return types
If I pass in an enum which knows the Class type of the value it keys, then
perhaps I can use generics to fix the return type.
This does not compile but gives a better idea of the kind of thing I mean.
Is it possible?
public class Preference {
public enum Key<T> {
A_KEY (String.class),
B_KEY (String.class),
C_KEY (Integer.class),
D_KEY (Integer.class);
Class<T> clazz;
Key(Class<T> c) {
clazz = c;
}
}; // end enum
public T get(Key<T> key) {
// stuff
return myT;
}
}
TIA
Object return types
If I pass in an enum which knows the Class type of the value it keys, then
perhaps I can use generics to fix the return type.
This does not compile but gives a better idea of the kind of thing I mean.
Is it possible?
public class Preference {
public enum Key<T> {
A_KEY (String.class),
B_KEY (String.class),
C_KEY (Integer.class),
D_KEY (Integer.class);
Class<T> clazz;
Key(Class<T> c) {
clazz = c;
}
}; // end enum
public T get(Key<T> key) {
// stuff
return myT;
}
}
TIA