Is there a Java method that determines if an instance of one Class<? extends Number>
can be converted losslessly into an instance of another Class<? extends Number>
?
Example method signature:
public static boolean canLosslessyConvert(Class<? extends Number> from, Class<? extends Number> to)
Examples of correct output:
canLosslessyConvert(Integer.class, Long.class) == true
canLosslessyConvert(Long.class, Integer.class) == false
canLosslessyConvert(Long.class, BigInteger.class) == true
A method in the Java 8 API is preferred, but if no such method exists, then methods in third-party libraries (like guava, spring, apache commons, etc.) are OK.