Java Object Type Case castToTypeOrNull(Object object, Class clazz)

Here you can find the source of castToTypeOrNull(Object object, Class clazz)

Description

cast To Type Or Null

License

Open Source License

Declaration

static <T> T castToTypeOrNull(Object object, Class<T> clazz) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    static <T> T castToTypeOrNull(Object object, Class<T> clazz) {
        return clazz.isInstance(object) ? clazz.cast(object) : null;
    }/*ww w  .  ja  va  2  s  .co m*/
}

Related

  1. castToArray(Object object)
  2. castToClass_strict(Number valueIn, Class toClassIn)
  3. castToObject(Object value)
  4. castToPrimitive(Object value, String targetType)
  5. castTotal(boolean isDoubleQuote, String target)
  6. castUnderLine(String origin)
  7. castValue(String value, Class clazz)
  8. castWithGenericsOrNull(Class base, Object obj)