What is the purpose of empty class in Kotlin?

后端 未结 6 1620
無奈伤痛
無奈伤痛 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:20

    tldr: they want to demonstrate it's possible

    even an empty class is of type Any and therefore has certain methods automatically. I think in most cases, this does not make sense, but in the documentation case it's used to show the simplest possible definition of a class.

    The Java equivalent would be:

    public final class Empty {
    }
    

提交回复
热议问题