0
votes

First of all, Manager (a Kotlin class) inherits from JavaPlugin (which is a Java class). This JavaPlugin class contains a getter method getPlugin(Class<T>).

Manager class:

class Manager : JavaPlugin() {

    companion object {
        [more code...]
        lateinit var plugin: Manager
            private set
    }

    [more code...]

}

Now back in any other Java class (my project is mixed between the two languages) I want to call Manager.getPlugin(), but in Java there is still only the method from the JavaPlugin class, which was inherited. In Kotlin files, I am able to retrieve plugin variable, but in Java files, I could not figure out how this possible.

I know that I could use Manager.Companion.getPlugin() now, but I do not want to change my old Java code (which contains the old static Manager.getPlugin() call).

Am I just wrong here with the companion object and should use something different in order to emulate my old static variable with a static getter? (I read that you could place the variables outside of the class, but I did not get how to access these variables then under the name Manager (it only worked with ManagerKt).)

I hope someone has a better title for this question and edits it.

1

1 Answers

2
votes