Here you can find the source of castOrDefault(Object o, Class
@SuppressWarnings("unchecked") public static <T> T castOrDefault(Object o, Class<T> type, T def)
//package com.java2s; //License from project: Apache License public class Main { @SuppressWarnings("unchecked") public static <T> T castOrDefault(Object o, Class<T> type, T def) { return o == null || !type.isInstance(o) ? def : (T) o; }/* www.ja va 2 s. co m*/ }