Function isInstanceOf

  • Check if this_obj is instance of other. This uses the native java instanceof operator. You may want to use this if JavaClass.instanceOf is overridden, as that method itself does not override any method defined in the specific java class named 'instanceOf'.

    Example

    import { instanceOf, importClass } from 'java-bridge';

    const ArrayList = importClass('java.util.ArrayList');
    const list = new ArrayList();

    isInstanceOf(list, ArrayList); // true
    isInstanceOf(list, 'java.util.ArrayList'); // true
    isInstanceOf(list, 'java.util.List'); // true
    isInstanceOf(list, 'java.util.Collection'); // true
    isInstanceOf(list, 'java.lang.Object'); // true
    isInstanceOf(list, 'java.lang.String'); // false

    // You can also use the instanceOf method (if not overridden)
    list.instanceOf(ArrayList); // true
    list.instanceOf('java.util.ArrayList'); // true
    list.instanceOf('java.util.List'); // true
    list.instanceOf('java.util.Collection'); // true
    list.instanceOf('java.lang.Object'); // true
    list.instanceOf('java.lang.String'); // false

    Type Parameters

    • T extends object

    Parameters

    • this_obj: JavaClass

      the object to check

    • other: string | T

      the class or class name to check against

    Returns boolean

    true if this_obj is an instance of other

Generated using TypeDoc