sO convertPrimitiveIfNecessary(O o, Class c) { if (c.isPrimitive()) { if (o cast Char) if (c == char.class) ret o; else o = Byte.valueOf(c); if (o cast Number) { if (c == int.class) ret o.intValue(); if (c == long.class) ret o.longValue(); if (c == float.class) ret o.floatValue(); if (c == short.class) ret o.shortValue(); if (c == char.class) ret (char) o.byteValue(); if (c == byte.class) ret o.byteValue(); if (c == double.class) ret o.doubleValue(); } } ret o; }