I have a class like this:
public class Pojo<T, P> {}
I know at compile time the type of T but I don't know the type of P. I was wondering if something like this is possible:
Class<Integer> t = Integer.class;
field = new Pojo<Integer, t>();
If not, any alternative solution to the problem is valid ;)
EDIT: I'm trying to obtain statistics from POJO fields, i.e, I have a class AirRegister with fields station, o3, so2, altitude, latitude... and I want to obtain the mode for these fields. The user can send any type with any field type to the program so until runtime the field type is unknown.
Example:
public static void main(String[] args) {
String field = args[0];
Class<fieldType> type = AirRegister.class.getDeclaredField(field).getClass();
ModeImpl<AirRegister, type> p = new ModeImpl<AirRegister, type>();
}
Objectand then doing run-time class checks). A generic with a class that isn't known until run time therefore isn't very useful as a generic. I can't propose an alternative solution unless I know what you're really trying to accomplish. For example, what does the inside of yourPojoreally look like? What were you hoping would happen when you instantiated yourPojo?