Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

Extern Classes

An extern class is an Aussom-side declaration that wraps a Java class. The functions inside it have no Aussom body - they map directly onto methods of the Java class. Most of the standard library is built this way: a small Java class implements the work, and an extern class makes it usable from Aussom.

You will mostly use extern classes, not write them. This page explains both sides.

Using an extern class

An extern class behaves like any other class once it is in scope. Static externs (the most common kind for stdlib modules) are called on the class name; instance externs are created with new.

The sys module is a good example. It is a static extern.

include sys;

class App {
    public main(args) {
        c.log(sys.getAssemblyPath());
        c.log(sys.getCurrentPath());
    }
}

You do not have to think about Java when you call into one of these modules. The runtime handles the bridge.

Reading an extern declaration

If you open one of the standard library .aus files (or the source of a host application), the declarations look like this:

static extern class sys : com.aussom.stdlib.ASys {
    public extern getSysInfo();
    public extern getAssemblyPath();
    public extern getCurrentPath();

    // ...
}

What each part means:

  • static - this is a singleton, called on the class name.
  • extern - the body is provided by Java, not Aussom.
  • class sys - the Aussom-facing name.
  • : com.aussom.stdlib.ASys - the fully-qualified Java class that implements the methods.
  • public extern getSysInfo() - a stub for a Java method. The function exists from Aussom's point of view, but the body is in Java.

Extern functions can declare argument types just like regular Aussom functions. Type-annotated extern arguments save the Java side from having to validate every call.

public extern parseInt(string Value);
public extern fileSize(string Path);

Inheriting from an extern class

A class may inherit from at most one extern class, mixed with any number of Aussom-side parents. This is how you build on a Java type while still adding Aussom methods.

class MyApp : AppBase {
    public index(req) {
        // ...
    }
}

AppBase is an extern class supplied by Aussom Server. MyApp inherits its routing and request infrastructure from Java, then adds the index route in Aussom.

You cannot inherit from more than one extern class.

Why extern classes exist

There are two main reasons:

  1. Performance. Hot paths and heavy work belong in Java. The extern wrapper lets Aussom call them with no extra overhead beyond the bridge.
  2. Reach. Java has a vast ecosystem (JDBC, HTTP clients, Firebase, JavaFX, ...). Extern classes are how Aussom exposes that ecosystem in a clean, Aussom-shaped API.

If you build your own Java host that embeds the Aussom interpreter, your custom classes register the same way. Aussom code running on your host gets a curated view of whatever your host wants to expose, and nothing more - the security manager makes sure of it.

What to read next

  • Standard Library - the extern classes that ship in the box.
  • Modules - how include finds extern modules at parse time.