public static < T > T castOrNull ( Object o , Class < T > cls ) { if ( o == null ) return null ; if ( cls . isInstance ( o ) ) return cls . cast ( o ) ; return null ; }
Cast object to class or return null .