I need to get the value of a field using reflection. It so happens that I am not always sure what the datatype of the field is. For that, and to avoid some code duplication
If you don't know the exact class of your number (Integer, Long, Double, whatever), you can cast to Number and get your long value from it:
Object num = new Integer(6); Long longValue = ((Number) num).longValue();