I have a existing class called "Customer". In this class, i want to create an EnumMap called "featureMap". The values in the EnumMap should implement the "FeatureInterface" interface. So far, I have only created the FeatureInterface, but I haven't implemented any classes that implement it.
Now, in the Customer class, the clone method is overridden. Since i have added the featureMap to this class, i also have to adapt the clone method to also clone the feature map. However, the clone method of EnumMap doesn't clone the values inside it; instead, it simply puts the existing instances into the new map. That's why I wanted to create a new map class that inherits from EnumMap and creates a clone instead of copying the object.
However, to do that, my FeatureInterface needs to override the clone method. Otherwise there wouldn't be a public clone method.
If I now want to override the clone method in the interface, I receive the Sonar warning "java:S2975". It suggests creating a constructor that expects an instance of the class itself as a parameter instead.
However, I believe that in an interface, I cannot specify that there must be a specific constructor. Am I correct? How would you approach this situation?
The rule is already being violated in the Customer class. However, since this code already existed, I didn't immediately notice it there.