Do we ever need empty class in java project? If yes then why?

917 views Asked by At

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?

1

There are 1 answers

0
Igor On

We can use it as type token e.g:

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

Also, read about usages in other languages to have deeper understanding of empty classes:

Kotlin: What is the purpose of empty class in Kotlin?

C#: Advantages of an empty class in C++