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

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -