Home » data types » Page 2

Tag Archives: data types

Each Enum Instance a different sub-class

Bipartite Graph

In this example we shall show you how to have each enum instance represent a different sub-class. To make each enum instance represent a different sub-class one should perform the following steps: Create an enum with different enum constants. Give each enum constant a different behavior for some method. Declare the method abstract in the enum type and override it with ...

Read More »

Enum to implement an interface

Bipartite Graph

With this example we are going to demonstrate how to use an enum to implement an interface. Implementing an interface with an enum can be useful when we need to implement some business logic that is tightly coupled with a discriminatory property of a given object or class. In short, to implement an interface with an enum you should: Create ...

Read More »

Enum for Singleton and Utility class

Bipartite Graph

enum Singleton { INSTANCE; } enum Utility { ; // no instances } Related Article: Java Secret: Using an enum to build a State machine Reference: Java Secret: Using an enum to build a State machine from our JCG partner Peter Lawrey at the Vanilla Java blog

Read More »