velocity-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Rall <...@finemaltcoding.com>
Subject Re: Object class check
Date Tue, 27 Aug 2002 09:19:07 GMT
Rickard Öberg <rickard@dreambean.com> writes:

> Is there an easy to way to check in a template whether an object
> implements a particular interface or not? I'd prefer to avoid having
> to code anything.

isAssignableFrom() might work (haven't tried it myself, tho).

http://java.sun.com/j2se/1.3/docs/api/java/lang/Class.html#isAssignableFrom(java.lang.Class)

context.put("impl", new HashMap());
context.put("interface", Map.class);

#if ($interface.isAssignableFrom($impl.getClass()))
  $impl.getClass().getName() is a $interface.getName()
#end
-- 

Daniel Rall <dlr@finemaltcoding.com>

--
To unsubscribe, e-mail:   <mailto:velocity-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-dev-help@jakarta.apache.org>


Mime
View raw message