What is the purpose of "&" in the generic type declaration?

9

In this code , the author creates a class as follows:

public abstract class GlyphIcon<T extends Enum<T> & GlyphIcons> extends Text { /* ... */ }

My question is to understand the meaning of this & in the following snippet:

<T extends Enum<T> & GlyphIcons>

So I noticed, GlyphIcons is an interface. So would that & have the same role as implements ? For example:

<T extends Enum<T> implements GlyphIcons>

Is this (or almost so)?

What does the "&" character mean? when used in generic type declaration?

    
asked by anonymous 20.02.2016 / 09:56

1 answer

7

The type of parameter that a generic type can handle can be limited by using the word extends ( Bounded Type Parameters ).

The constraint is done indicating the class of which extends and / or interfaces it implements.

The & is used to separate multiple boundaries.

If a boundary is a class, it must be specified first.

    
20.02.2016 / 13:18