So far, we have been working with parties in which the party members were sociable animals. However, it is difficult to enjoy a party without some music. The sociable animals need to hear something in order to make them dance and enjoy their party. We want to create a party of sociable animals and something hearable.
Now, we will create a new interface that we will use as a constraint later when we define another class that takes advantage of generics with two constrained generic types. The following lines show the code for the Hearable
interface. This interface specifies the requirements that a type must meet in order to be considered as hearable, that is, a generator of music for a party in our application domain. The public
modifier followed by the interface
keyword and the interface name, Hearable
, composes the interface declaration, as follows.
The code file for the sample is included in the java_9_oop_chapter_11_01...