DeepMedia logo
Open Source

Search...

Objects

Annotating objects

Whenever you declare an object, you can use the @KneeObject annotation to tell the compiler that it should be processed. Knee supports objects in different scenarios:

  • top level objects
  • objects nested inside another declaration
  • companion objects
kotlin logokotlin
@KneeObject object Foo { ... } class Utilities { @KneeObject object Bar { ... } @KneeObject companion object { ... } }

Under the hood, objects are not actually serialized and passed through the JNI interface: since there can only be a single instance of an object, no extra information is needed and the compiler can retrieve the object field statically on both platforms.

Annotating members

All callable members (functions, properties, constructors) of an object can be made available to the JVM side, but they must be explicitly marked with the @Knee annotation as described in the callables documentation.

kotlin logokotlin
@KneeObject object Game { @Knee fun start() { ... } fun loop() { ... } }

In the example above, only the start function will be available on the JVM side.

Importing objects

If you wish to annotate existing objects that you don't control, for example those coming from a different module, you can technically use @KneeObject on type aliases. Unfortunately as of now, this functionality is very limited in that you can't choose which declarations will be imported.

Subscribe to the DeepMedia Newsletter

The latest news about DeepMedia products, open source projects and software development at our company.

By clicking “Subscribe”, you agree that DeepMedia may use your email address to send you newsletters, including commercial communications, and to process your personal data for this purpose. You agree that DeepMedia may process said data using third-party services for this purpose in accordance with the DeepMedia Privacy Policy. You can revoke this consent at any time using the unsubscribe link included in each email or by writing at contact@deepmedia.io.