Java: Object to long
long toLong(Object object) {
if (object instanceof Long) {
return (Long)object;
} else if (object instanceof Integer) {
return (Integer)object;
} else if (object instanceof String) {
return Long.parseLong((String)object);
}
return Long.parseLong(object.toString());
}
System.out.println(toLong(Integer.MAX_VALUE));
System.out.println(toLong(Long.MAX_VALUE));
System.out.println(toLong("1"));