Java Object Create as(Class type, U o)

Here you can find the source of as(Class type, U o)

Description

if o is of the given type, returns o cast to it; otherwise returns null.

License

Open Source License

Declaration

public static <T extends U, U> T as(Class<T> type, U o) 

Method Source Code

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

public class Main {
    /**/*  w  w  w  . j a v  a2s  .c  om*/
     * if o is of the given type, returns o cast to it; otherwise returns null.
     */
    public static <T extends U, U> T as(Class<T> type, U o) {
        if (type.isInstance(o)) {
            return (T) o;
        }
        return null;
    }
}

Related

  1. as(Class clazz, I instance)
  2. as(Class cls, Object o)
  3. as(Class t, Object o)
  4. as(Class targetClass, Object entity)
  5. as(Class type, Object value)
  6. as(Object cst)
  7. as(Object instance, Class clazz)
  8. as(Object o)
  9. as(Object o, Class clazz)