Here you can find the source of as(Object o, Class
Parameter | Description |
---|---|
T | a parameter |
o | a parameter |
clazz | a parameter |
@SuppressWarnings("unchecked") public static <T> T as(Object o, Class<T> clazz)
//package com.java2s; //License from project: Open Source License public class Main { /**/*w w w . j a v a2 s. c o m*/ * Attempts to cast to the specified type, returns null if not castable. Useful with generics, and avoids spreading warnings throughout the code. * * @param <T> * @param o * @param clazz * @return */ @SuppressWarnings("unchecked") public static <T> T as(Object o, Class<T> clazz) { if (o == null) return null; if (!clazz.isAssignableFrom(o.getClass())) return null; return (T) o; } }