What is the purpose of empty class in Kotlin?

后端 未结 6 1621
無奈伤痛
無奈伤痛 2021-01-04 21:08

I was going through Kotlin reference document and then I saw this.

The class declaration consists of the class name, the class header (

6条回答
  •  悲哀的现实
    2021-01-04 21:26

    It doesn't make much sense as a final result. However it can be useful in active development and at a design time as a placeholder of some sort, which may be expanded in the future. Such terse syntax allows you to quickly define such new types as needed. Something like:

    class Person (
        val FirstName: String,
        val LastName: String,
        // TODO
        val Address: Address
    )
    
    class Address
    

    I think main reason this is specifically mentioned in documentation is to demonstrate, that language syntax in general can be terse, not that it is specifically created for common usage.

提交回复
热议问题