android/kotlin-guides

Companion object

Closed this issue · 4 comments

Is the recommendation for companion objects? Should they be at the bottom or top of a class?

From what I read the relevant part of the style is this:

The order of members within a class follow the same rules as the top-level declarations.

So the rule is logical order of the declarations. If your companion object is public and contains public constants, then I suppose it's logical to have it on top. If it's private and contains only e.g. configuration constants then you may want to have it on bottom.

Yep that's it.

Are they the most important thing? Put them first. Are they boring constants? Last.

You have to decide.

According to coding conventions of Kotlin, companion objects should be in the bottom. More info at:
https://kotlinlang.org/docs/reference/coding-conventions.html

What's the reasoning behind putting companion object at the bottom?