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

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

Description

cast

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <T> T cast(Class<T> clazz, Object object) 

Method Source Code

//package com.java2s;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> T cast(Class<T> clazz, Object object) {
        if (clazz.isAssignableFrom(object.getClass())) {
            return clazz.cast(object);
        }//from w  w  w .  j  a  va2  s. c  o m
        throw new ClassCastException("Cannot cast class " + object.getClass().getName() + ", whose classloader is "
                + object.getClass().getClassLoader() + ", to class " + clazz + ", whose classloader is "
                + clazz.getClassLoader());
    }
}

Related

  1. cast(byte[] bytes)
  2. cast(Class c)
  3. cast(Class c, Object o)
  4. cast(Class clazz, Object o, T def)
  5. cast(Class clazz, Object obj)
  6. cast(Class targetClass, Object obj)
  7. cast(Class toType, Object value)
  8. cast(Class type, Object key, Object value)
  9. cast(Class type, Object obj)