Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

lachoy (1663)

lachoy
  chris.winters@gmail.com
http://www.cwinters.com/

I am actually Chris Winters; I am actually living in Pittsburgh, Pennsylvania, USA; I am actually married and have three cats. (Guess what one of them is named?) I am the "OpenInteract" guy, which could be good or bad.

Journal of lachoy (1663)

Tuesday June 21, 2005
08:10 AM

One of those java features I should have known: class.isInstance()

[ #25298 ]
One of the few times I've written a piece of functionality and actually found it later: the isInstance() method of the Class class. It's useful when you're dealing with generic classes and therefore cannot use instanceof:

void ensureAllHaveParent( Collection c, Class parentClass ) {
    for ( Iterator it = c.iterator(); it.hasNext(); ) {
        Object o = it.next();
        if ( ! ( o instanceof parentClass ) ) ... // WRONG!
        if ( ! parentClass.isInstance( o ) )  ... // RIGHT!
    }
}

Posted from cwinters.com; read original

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.