Strengthen bounded type parameters

suggest change

Bounded type parameters allow you to set restrictions on generic type arguments:

class SomeClass {

}

class Demo<T extends SomeClass> {

}

But a type parameter can only bind to a single class type.

An interface type can be bound to a type that already had a binding. This is achieved using the & symbol:

interface SomeInterface {

}

class GenericClass<T extends SomeClass & SomeInterface> {

}

This strengthens the bind, potentially requiring type arguments to derive from multiple types.

Multiple interface types can be bound to a type parameter:

class Demo<T extends SomeClass & FirstInterface & SecondInterface> {

}

But should be used with caution. Multiple interface bindings is usually a sign of a code smell, suggesting that a new type should be created which acts as an adapter for the other types:

interface NewInterface extends FirstInterface, SecondInterface {

}

class Demo<T extends SomeClass & NewInterface> {

}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Interfaces:
* Strengthen bounded type parameters

Table Of Contents
8 Arrays
9 Interfaces
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap