Skip to content

Latest commit

 

History

History
47 lines (40 loc) · 1.94 KB

Follow-up New Class Object Syntax.md

File metadata and controls

47 lines (40 loc) · 1.94 KB
title date author tags keywords categories reward reward_title reward_wechat reward_alipay source_url translator translator_url
Follow-up: New Class Object Syntax
2015-03-14 03:57:00 -0700
Andrey Breslav
官方动态
false
Have a nice Kotlin!

In the previous post I explained the rethought design of what used to be called “class objects”: they are now more uniform with normal nested objects, have names (name may be omitted, but a default one will be used by the compiler), and we can write extensions to them. One of the goals of that post was to gather feedback on the term we proposed, namely “default object”, and many of you rightfully stated in the comments that the term has a disadvantage: it is easily misread for “a default instance of the class”. Now we are looking for a better term and need some more feedback… Update: thanks to everyone, with your help, we chose companion. We are talking about a modifier in front of the word object:

{% raw %}

{% endraw %}
class KotlinClass {
    ??? object {
        fun callMeOnTheClassName() { ... }
    }
}

{% raw %}

{% endraw %}

Our candidates are:

  • default object
  • attached object
  • companion object
  • manifest object

We’d be very grateful if you shared your thoughts about these candidates in the comments. Thanks! P.S. There was a proposal of simply using a naming convention instead of a modifier. This comment explains why we decided in favour of a modifier. Also note that this convention would be used a lot more often than others, and others are subject to reconsideration under the upcoming language design review.