Java converts an object of type Object to a specified type

    public static <T> T cast(Object o, Class<T> type) {
    
    
        if (type.isInstance(o)) return type.cast(o);
        throw new RuntimeException("can not cast " + o.getClass() + " to '" + type);
    }
    

Guess you like

Origin blog.csdn.net/daiyi666/article/details/120107673