Java Generics name clash, method not correctly overriden
Posted
by Shervin
on Stack Overflow
See other posts from Stack Overflow
or by Shervin
Published on 2010-03-30T09:02:53Z
Indexed on
2010/03/30
9:03 UTC
Read the original article
Hit count: 500
Hi.
I have seen different questions regarding this, but I still find this topic to be very confusing.
All I want to do, is have an abstract class that implements an interface, and have a class extending this abstract class so that the hard class needs to implement getKommune()
and setKommune(Kommune kommune)
, but not the other method, because that is in the abstract class.
I have the following interface.
public interface KommuneFilter {
<E extends AbstractKommune<?>> void addKommuneFromCurrentUser(E e);
Kommune getKommune();
void setKommune(Kommune kommune);
}
And this Abstract class
public abstract class AbstractKommune<E extends AbstractKommune<?>> implements KommuneFilter {
@PrePersist
void addKommuneFromCurrentUser(E e) {
}
}
And I want to use it like this
public class Person extends AbstractKommune<Person> {
private Kommune kommune;
public void setKommune(Kommune kommune) {this.kommune=kommune;}
public Kommune getKommune() {return kommune;}
}
However, I get
Name clash: The method of has the same erasure of type but does not override it
Why isn't it correctly overriden?
© Stack Overflow or respective owner