Java Object Type Case castOrDefault(Object o, Class type, T def)

Here you can find the source of castOrDefault(Object o, Class type, T def)

Description

cast Or Default

License

Apache License

Declaration

@SuppressWarnings("unchecked")
    public static <T> T castOrDefault(Object o, Class<T> type, T def) 

Method Source Code

//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*/
}

Related

  1. castNumber(Number num, Class clazz)
  2. castObject(Class clazz, Object object)
  3. castObject(Object fromObj, Class toClass)
  4. castObject(Object ob)
  5. castOrDefault(Class type, Object value, T defaultValue, boolean allowNull)
  6. castOrNull(Object o, Class clazz)
  7. castOrNull(Object o, Class cls)
  8. castOrThrowError(Class clazz, T1 object, String messageTemplate)
  9. castSafe(Class inClass, Object inValue, T inDefault)