interface and a class. name clash: same erasure, yet neither overrides other
Your GenericQueue
is implementing the raw interface IGenericQueue
, so its T
is different than the T
in IGenericQueue
. Add the <T>
in the implements
clause:
public class GenericQueue<T extends Comparable> implements IGenericQueue<T> {
// ^^^
so you are implementing the generic interface with the same T
.
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<U> {...}
public interface SetExtended<U> extends Set<U> {...}
public abstract class AbstractSetExtended<U> implements SetExtended<U>{...}
public class Set1<U> extends AbstractSetExtended<U> {...}
public class Set2<U> extends AbstractSetExtended<U> {...}
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