down cast object - Java Reflection

Java examples for Reflection:Object

Description

down cast object

Demo Code


//package com.java2s;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> T downcast(Class<T> klass, Object actual) {
        if (actual != null && klass.isAssignableFrom(actual.getClass()))
            return (T) actual;
        else/* w w  w  . j a  v a  2  s. c o  m*/
            return null;
    }
}

Related Tutorials