What is the advantage of "companion object" vs static keyword

I’m saying that using statics is often a bad code-smell, an anti-pattern, in a number of ways. Inability to have overloading, or problems mocking static methods for unit testing - have all bitten the code I’ve been working on in the past.
Those are real-life pragmatic issues.

But if you must have something that the JVM sees as a static, for reasons of interoperability, then add annotations where you must.

And otherwise, I fail to see a big deal in it. I really can’t.

Others have already tried answering the question in the subject of the thread: what advantages are there?

But it seems you persist in only being able to see disadvantages, and insist on adding a particular feature to the language only because it suites you, and because “other languages have it too!”. Which is not a very strong argument - just because all the other lemmings walked over the edge, should I do it too?

1 Like