You are currently viewing Why are companion objects?

Why are companion objects?

Hey all, doing some self-training and I’m currently going through a Kotlin course. The instructor just went over companion objects, and while I do understand how they broadly work, I don’t understand why they exist.

This is undoubtedly to do with the fact that Python is the lowest level language I’ve used so far, and Kotlin being a Java replacement, it has a lot more configurability in terms of public/private and so forth than what I’m used to.

I’m taking it on faith that at some point as I start learning to make apps, the need for this will become clear organically, but if someone can point me in the direction of some good reading to supplement this course (either on Kotlin/Java in particular, or Android dev more generally, or even on transitioning from Python to a lower-level tongue), I would be very interested in that.

I certainly don’t think Jetbrains threw this functionality in for the heck of it, but at this point it’s rather mysterious to me.

submitted by /u/JTode
[link] [comments]