Software Development

Kotlin – create static fields and methods

This post demonstrates how to create static class members similar to that of Java. We use Kotlin 1.1 here.

All static members Class

If we want to create a class that only contains static members, we use singletons in Kotlin. For example:



Static and non-static members in class


Sometimes we have classes that have both static and non-static class members in Java. In Kotlin, we can mix static and non-static members in one class. For example:




Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like