The java.lang.Number class and related classes make most of this work just fine. If you need additional support for handling zeros and primitives without writing checks and conditional expressions, check out the Apache Commons-Lang libraries, in particular NumberUtil.class. These are mature, commonly used, and well-documented libraries.
source
share