📜 ⬆️ ⬇️

Unusual generics behavior

Accidentally discovered an atypical problem with parameterization and inheritance in Java.
At once I will make a reservation that all this is only of academic interest . In real life, nobody will be so crooked. But formally this should not be:
Interface.java
public interface Interface {
void test (Class <Object> clazz);
}

BaseClass.java
public abstract class BaseClass <T> implements Interface {
abstract public void test (Class <Object> clazz);
}

Myclass.java
public class MyClass extends BaseClass {
public void test (Class <Object> clazz) {
}
}
The compiler gives an error:
MyClass is not abstract and does not override an abstract method test (java.lang.Class)

')

Source: https://habr.com/ru/post/59135/


All Articles