2

In empty class (without field and properties) also compiler automatically creates a default constructor after compiling. If we never use this empty class then why compiler creates this default constructor?

4

1 回答 1

1

我们可以将其用作类型标记,例如:

class DatabaseColumnName {}
class DatabaseTableName {}
addItem(DatabaseColumnName.class, "Age")
addItem(DatabaseTableName.class, "Person")
...
getItemsByType(DatabaseTableName.class)

此外,阅读其他语言的用法以更深入地了解空类:

Kotlin:Kotlin中空类的目的是什么?

C#:C++ 中空类的优点

于 2017-12-01T14:15:42.627 回答