interface and a class. name clash: same erasure, yet neither overrides other

前端 未结 3 1522
囚心锁ツ
囚心锁ツ 2020-12-01 09:16

I have an interface, and when I try to implement one of its methods, I get this error : \"name clash: enqueue(T#1) in GenericQueue and enqueue(T#2) in IGenericQueue have the

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 09:33

    I was having a similar problem, although I have a more complicated generic class hierarchy following the template pattern for OO programing. Where there is an interface then another interface extending that interface then an abstract class implementing that interface then classes extending the abstract class, but was getting the error "interface and a class. name clash: same erasure, yet neither overrides other" And found that only when I put or after every single class in the hierarchy and in every reference to that class would the error go away. For example:

    public interface Set {...}
    public interface SetExtended extends Set {...}
    public abstract class AbstractSetExtended implements SetExtended{...}
    public class Set1 extends AbstractSetExtended {...}
    public class Set2 extends AbstractSetExtended {...}
    

    The template pattern is great for modular design, as well as factoring out common code and good for code reuse. To read a little more about the template pattern: https://en.wikipedia.org/wiki/Template_method_pattern

提交回复
热议问题