java - Enforce subclass to declare a enum -



java - Enforce subclass to declare a enum -

can enforce kid classes create enum in them?

class document<t extends enum<t>>{ map<t, string> fields; } class textdocument extends document<textdocument.field>{ public enum field{ ... } }

how can enforce implementation of document have enum named field within it? in above example, textdocument can extend document other enum (say graphdocument.field) shouldn't allowed. how can create restriction? need enforce rule subclasses - "you must have own enum". possible? hacky way? ideas?

in short, can't. however, can forcefulness homecoming array of values of particular enumeration. can forcefulness enumeration implement interface.

public interface someinterface { // methods want able perform on enums } public abstract class somesuperclass<t extends someinterface> { abstract t[] getsome(); } public class somesubclass extends somesuperclass<someinterface> { public enum someenum implements someinterface { testenum { // interface implementation } } public someinterface[] getsome() { homecoming someenum.values(); } }

this pretty awkward solution, works.

java generics enums subclass

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -