I have a method that requires something like Double.class as one of its inputs;
e.g.
someOutput = SomeObj.someMethod("parameter",Double.class);
I have another class that has a bunch of fields of different datatypes that I'd like to feed as input to this method in stead of explicitly writing Double.class of Integer.class etc etc.
I know this involves java reflection, but I'm not quite sure how to do what I want. I'm trying something like this but it isn't working:
for(Field field : Class.forName(MyClassWithLotsOfFields.class.getCanonicalName()).getFields()){
someOutput = SomeObj.someMethod("parameter",field.getClass());
//Do more stuff here...
}
but field.getClass() is not giving me the actual class of the field from MyClassWithLotsOfFields but instead java.lang.reflect.Field
any ideas for how to do what I want?
Class.forName(MyClassWithLotsOfFields.class.getCanonicalName())instead of justMyClassWithLotsOfFields.class?Field, which you already know about.