Java examples for Reflection:Object
if o is of the given type, returns o cast to it; otherwise returns null.
//package com.java2s; public class Main { /**/*from w ww . ja v a 2 s . c o m*/ * 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; } }