Note that there are some explanatory texts on larger screens.

plurals
  1. POJava generics of generics of
    primarykey
    data
    text
    <p>I have a generic class which represents a fragment of text. That fragment of text may have any of a number of different modes (different types of highlighting). Those modes are represented by an Enum. The Enum could be different for each project but it must implement an interface which provides a method to combine 2 of them (could be highlighted and bolded). So i have an interface:</p> <pre><code>public interface TextFragmentMode&lt;E extends Enum&lt;E&gt;&gt; { /** * Will combine the supplied mode with the current mode and return the * result. * * @param mode The mode to combine with. * @return The combined mode. */ public E combine( E mode ); } </code></pre> <p>Then my TextFragment is a container for both a String of text, and a mode. But when I try to declare the class:</p> <pre><code>public class TextFragment&lt;E extends TextFragmentMode&lt;E extends Enum&lt;E&gt;&gt;&gt; { StringBuilder text; E mode; ... </code></pre> <p>I get the following error:</p> <blockquote> <p>Syntax error on token "extends", , expected</p> </blockquote> <p>Which, according to eclipse syntax highlighting, is referring to the</p> <pre><code>E extends Enum&lt;E&gt; </code></pre> <p>portion of the code. Does anyone know what I am doing wrong? I must be missing something about Generics...</p> <p>--------------------- edit ------------------- </p> <p>I'm finally taking the time to read Effective Java by Josh Bloch (second edition), and it turns out he goes over this use case as <em>Item 34: Emulate extensible enums with interfaces</em>. As much as I would like to say great mind think alike... That would be WAY too presumtuous!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload