A thought aloud.

As more and more of my code and several libraries that I use slide towards
generics I have found 'class.isInstance' far more useful than 'instanceOf',
to the point where I literally never use it.

http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Class.html#isInstance%28java.lang.Object%29

if (beanManager instanceof WebappBeanManager) {

Simply becomes...

if (WebappBeanManager.class.isInstance(beanManager)) {

For example, should 'WebappBeanManager' ever become 'WebappBeanManager<T>'
(Probably a bad example here, but you get the idea) then instanceOf will
break silently.

I have never benchmarked it, but am quite sure the overhead is negligible.

I would like to suggest that we prefer to use it. What do you think?

Andy.



--
View this message in context: 
http://openejb.979440.n4.nabble.com/Generics-safety-class-isInstance-vs-instanceOf-tp4660675.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Reply via email to