Skip to content

Instantly share code, notes, and snippets.

@abreslav
Created October 29, 2014 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abreslav/9f595c6c923827d0dce5 to your computer and use it in GitHub Desktop.
Save abreslav/9f595c6c923827d0dce5 to your computer and use it in GitHub Desktop.

Calling a class object member from Java:

public class Engine private() {
    class object {
        public fun getInstance(): Engine = Engine()
    }
}

Option 1: class object is an object, so you can access its members as instance methods through a static constant:

// Java
Engine.OBJECT$.getInstance()

Option 2: use [platformStatic] annotation:

public class Engine private() {
    class object {
        [platformStatic]
        public fun getInstance(): Engine = Engine()
    }
}

Then, this method becomes static (the previous option still works):

// Java
Engine.getInstance()

More details: http://kotlinlang.org/docs/reference/java-interop.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment