Dishonered
Dishonered

Reputation: 8851

Should object definitions in sealed classes start with capital or lowercase letter?

For example :

sealed class Event {
  object ViewClicked : Event()
}

Should it be ViewClicked or viewclicked? It seems its a variable , so i guess it should be viewclicked but the rest of the codebase on the app has capitalized objects. So i wanted to know whats the right approach here?

Also , can anyone confirm if object is like a static variable in Java?

Upvotes: 1

Views: 524

Answers (1)

Sergio
Sergio

Reputation: 30755

ViewClicked is not a variable. Declaring object ViewClicked we show that we have only one instance (singleton) of class ViewClicked, so it is definition of a class and creation of its instance on one line.

By Kotlin style guide:

Names of classes and objects start with an upper case letter and use the camel case.

Therefore the correct definition would be:

sealed class Event {
    object ViewClicked : Event()
}

Upvotes: 4

Related Questions