public final class Converter extends Object
public static Object convert(Object fromInstance, Class toType)
Examples: Long x = convert("35", Long.class); Date d = convert("2015/01/01", Date.class) int y = convert(45.0, int.class) String date = convert(date, String.class) String date = convert(calendar, String.class) Short t = convert(true, short.class); // returns (short) 1 or (short) 0 Long date = convert(calendar, long.class); // get calendar's time into long
fromInstance
- A value used to create the targetType, even though it may
not (most likely will not) be the same data type as the targetTypetoType
- Class which indicates the targeted (final) data type.
Please note that in addition to the 8 Java primitives, the targeted class
can also be Date.class, String.class, BigInteger.class, and BigDecimal.class.
The primitive class can be either primitive class or primitive wrapper class,
however, the returned value will always [obviously] be a primitive wrapper.Copyright © 2015. All rights reserved.