Here you can find the source of coerce(Object value, Class
public static <T> T coerce(Object value, Class<T> clazz)
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by public class Main { public static <T> T coerce(Object value, Class<T> clazz) { return coerce(value, clazz, null); }// ww w .j av a 2 s.c o m public static <T> T coerce(Object value, Class<T> clazz, T def) { if (value == null) { return def; } else if (clazz == Integer.class) { return (T) Integer.valueOf(((Number) value).intValue()); } else if (clazz == Double.class) { return (T) Double.valueOf(((Number) value).doubleValue()); } else if (clazz.isInstance(value)) { return clazz.cast(value); } throw new ClassCastException("Cannot cast " + value + " to " + clazz); } }