https://kotlinlang.org logo
#getting-started
Title
# getting-started
i

igor.wojda

11/22/2021, 2:16 PM
I wonder about coding conventions - the class layout:
Copy code
The contents of a class should go in the following order:

Property declarations and initializer blocks

Secondary constructors

Method declarations

Companion object
What would be the reasoning of placing companion object at the end? (just personal style, or there is some actual argument behind it?)
p

pavi2410

11/22/2021, 2:22 PM
I guess it's because it's least touched / remains constant mostly.
m

Marko Novakovic

11/22/2021, 2:22 PM
I was wondering the same thing about
companion object
but it didn’t cross my mind to ask here 😄 and it’s good idea I used to put it first, above everything
@pavi2410 makes sense. in Java for example statics are defined first, on the very top of the class tho 😕 🤔
p

pavi2410

11/22/2021, 2:24 PM
Must be a Kotlin-thing as syntax could influence on the position. I put `const val`s at the very top too.
3 Views