I am looking for a simple, concise way to convert a given Number object to an object of a given numeric type.
- Loss of precision due to narrowing conversions is fine
- I prefer not to go through strings.
I need something like:
private static Number convert(Number num, Class<? extends Number> targetType)
Is there a way to do it without checking all the combinations of types?