I have a piece of code where i need to pass the class of a field in a method. Because of the mechanics of my code i can only handle reference objects only and not primitives. I want an easy way of determining if a Field's type is primitive and swap it with the appropriate wrapper class. So in code what i do so far is something like this :
Field f = getTheField(); // Dummy method that returns my Field
Class<?> c = f.getType();
if (c == int.class)
c = Integer.class;
if (c == float.class)
c = Float.class;
// etc
myMethod(c);
This works fine except for the fact that i need to explicitly check for all the primitive types and swap them with the appropriate wrapper class. Now i now that they are not so many and it won't be a problem to simply list them all but i was wondering if there was an easier and more elegant way of doing it.