Skip to content
Advertisement

Difference between a class and object in Kotlin

I’m new to Kotlin and have recently converted a simple file from java to Kotlin. I am wondering why the Android converter changed my java class to a Kotlin object.

Java:

JavaScript

Converted Kotlin:

JavaScript

Why wasn’t it:

JavaScript

Any help would be greatly appreciated thanks.

Advertisement

Answer

A Kotlin object is like a class that can’t be instantiated so it must be called by name. (a static class per se)

The android converter saw that your class contained only a static method, so it converted it to a Kotlin object.

Read more about it here: http://petersommerhoff.com/dev/kotlin/kotlin-for-java-devs/#objects

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement