tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Jackson" <mjack...@cdi-hq.com>
Subject RE: instance of (ot)
Date Thu, 20 Feb 2003 19:06:03 GMT
Perhaps you ought to post a snippet of what doesn't work.  I personally
haven't had any problems with "instanceof", but without seeing what you're
doing I don't think any of us can help.

--mikej
-=-----
mike jackson
mjackson@cdi-hq.com

> -----Original Message-----
> From: Felipe Schnack [mailto:felipes@ritterdosreis.br]
> Sent: Thursday, February 20, 2003 11:01 AM
> To: Tomcat Users List
> Subject: instance of (ot)
>
>
>   I would like to use instanceof's keyword funcionality.
>   The problem is that I want to test if a class is subclass of a
> java.lang.Class object... There is a way? Instanceof keyword doesn't
> work, so I implemented the following, but I'm not very proud of myself:
>
> 	private boolean instanceOf(Object obj, Class clasz)
> 	{
> 		if (obj == null || clasz == null) return false;
> 		Class objClass = obj.getClass();
> 		Class[] classes = objClass.getClasses();
> 		if (classes == null) return false;
> 		for (int i = 0; i<classes.length; i++)
> 		{
> 			if (classes[i].equals(clasz)) return true;
> 		}
> 		while (objClass != null)
> 		{
> 			if (objClass.equals(clasz)) return true;
> 			objClass = objClass.getSuperclass();
> 		}
> 		return false;
> 	}
>
>
> --
>
> Felipe Schnack
> Analista de Sistemas
> felipes@ritterdosreis.br
> Cel.: (51)91287530
> Linux Counter #281893
>
> Centro Universitário Ritter dos Reis
> http://www.ritterdosreis.br
> ritter@ritterdosreis.br
> Fone/Fax.: (51)32303341
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message