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

Jonathan Ellis

06/09/2022, 8:31 PM
Does idiomatic Kotlin use classes to organize code or is that a relic of my Java background? Specifically, is it good form to group related stateless functions in a class's companion object, or is it better to use a sub-package?
l

Luke

06/09/2022, 8:46 PM
I would say: don't create a class just to have a companion. In that case, define the functions directly in a file. I would only define functions in a companion if it makes sense semantically to call it via the class name. Maybe something to keep in mind is that the Kotlin team is working on a namespace feature which is probably what you want
l

Landry Norris

06/09/2022, 9:28 PM
I’ve found that I use objects a lot more than classes after switching to Kotlin.
j

Jonathan Ellis

06/09/2022, 10:23 PM
Thanks!
4 Views