Class JavaClass

A class to be extended for custom class definitions. This does not allow for any methods to be called if not defined in the class definition.

This is also just a definition for creating typescript definitions for java classes. This does not actually create a java class.

If you want to create a java class inside of typescript, take a look at this test helper. For implementing interfaces, take a look at the newProxy function.

Example

import { importClass } from 'java-bridge';

declare class PersonClass extends JavaClass {
public constructor(name: string, age: number);
public newInstanceAsync(name: string, age: number): Promise<Person>;

public getName(): Promise<string>;
public getNameSync(): string;
public getAge(): Promise<number>;
public getAgeSync(): number;
}

class Person extends importClass<typeof PersonClass>('com.test.Person') {}

const person = new Person('John', 20);
console.log(person.getNameSync()); // John
console.log(person.getAgeSync()); // 20

Hierarchy (view full)

Constructors

Properties

class.proxy: JavaClassProxy

The class proxy class instance

Accessors

Methods

  • Default java equals implementation. Async call.

    Parameters

    Returns Promise<boolean>

    true if this matches o

  • Default java equals implementation. Sync call.

    Parameters

    Returns boolean

    true if this matches o

  • Java default hashCode method. Async call.

    Returns Promise<number>

  • Check if this is an instance of another class. Pass either the name of the other class or the class itself to check if this is an instance of it. Does not overwrite any existing instanceof operator. This uses the native java instanceof operator.

    This method's name is not affected by the JavaConfig#syncSuffix and JavaConfig#asyncSuffix options.

    Example

    import { importClass } from 'java-bridge';

    const JavaString = importClass('java.lang.String');
    const str = new JavaString('Hello World');

    str.instanceOf(JavaString); // true
    str.instanceOf('java.lang.String'); // true
    str.instanceOf('java.lang.Object'); // true
    str.instanceOf('java.lang.Integer'); // false

    Type Parameters

    • T extends object

    Parameters

    • other: string | T

      the class to check if this is an instance of

    Returns boolean

    true if this is instance of other

Generated using TypeDoc