Log in

Posts Tagged ‘OO’

Feb
01
in Java

I’ve fallen in love with Java’s instanceof; it makes me feel a bit more at home when i’m away from my beloved Ruby. I recently ran into a situation where i needed to determine if an object implemented a specific interface and it turns out that instanceof is just the tool to do it.

    Vector foo = new Vector();
    boolean comparable = foo instanceof Comparable; // false, Vector doesn't implement Comparable
    boolean serializable = foo instanceof Serializable;   // true, Vector does implement Serializable