There is no static keyword
in kotlin.
what is the equivalent of java static class
in kotlin?
There is no static keyword
in kotlin.
what is the equivalent of java static class
in kotlin?
If you just declare a class inside another class, the inner class can be instantiated without an instance of the outer class, similar to Java static classes:
class Outer {
class Inner
}
// can do "Outer.Inner()" directly without an instance of Outer
You don't need any modifiers.
If you want something similar to Java's non-static classes, you would need to add the word inner
:
class Outer {
inner class Inner
}
// need an instance of Outer to create an instance of Outer.Inner
To summarise:
needs an outer instance | does not need an outer instance | |
---|---|---|
Java | no modifier | static |
Kotlin | inner |
no modifier |