Here you can find the source of as(Class
public static <T extends U, U> T as(Class<T> type, U o)
//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; } }