I need to define an Interface that redefines something like a hashset.
So I have methods to of the type get(byte key). As I can not use descriptive keys like String I am looking for a generic way to define the keys available within some implementation of the interface. I think of using an enum for that. But is it possible to force the definition of such Enum within the Interface?
To make clear what I mean lets look on an example class implementing the Interface:
public class ByteHashsetImpl implements ByteHashset {
public enum Key {
STATE_A,
STATE_B,
STATE_C;
}
public enum Value {
VALUE_A,
VALUE_B,
VALUE_C;
}
public void get(Key k) {
/**/
}
}
I want to ensure that each implementation defines and uses its own Enums called Key and Value. This would make it possible to access the key/values using something like ByteHashsetImpl.Key for every implementation of the interface.
Is it possible at all or is there another option beside an informal definition like coding quideline?
You can’t enforce the creation of such enums, but you can force a type argument to be an enum:
In this case a
Frobnicatorcould simply re-use an existingenumclass, butEinFrobnicatorwill always be anenumtype.