as(), casts the argument or returns null if it's not an instance of

the specified class.
Yeah.
I've had this laying around for a long time, almost embarrassed by it.
But I keep running into places where it'd be handy, and now I'm
going for it.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2940 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray.j.greenwell
2010-11-09 00:53:26 +00:00
parent 019e5f9311
commit 7301369760
@@ -32,6 +32,14 @@ import com.samskivert.annotation.*;
*/
public class ObjectUtil
{
/**
* Cast the specified Object, or return null if it is not an instance.
*/
public static <T> T as (Object obj, Class<T> clazz)
{
return clazz.isInstance(obj) ? clazz.cast(obj) : null;
}
/**
* Test two objects for equality safely.
*/