tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felipe Schnack <feli...@ritterdosreis.br>
Subject instance of (ot)
Date Thu, 20 Feb 2003 19:01:07 GMT
  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


Mime
View raw message