다음 코드가 작동하지 않는 이유를 설명 할 수 있습니까? 나는 이런 식으로 썼다면일반 오류 : 클래스가 인수에 적용되지 않습니다.
The method getAliasForEntityClass(Class<? extends Entity>) in the type EntityManager is not applicable for the arguments
(Class<capture#1-of ? extends Textable>)
, 나는 오류가 없었어요 :
public class TestGeneric {
EntityManager entityManager = new EntityManager();
public <T extends Entity & Textable> void doAction(T obj) {
entityManager.getAliasForEntityClass(obj.getClass());
}
}
class EntityManager {
public String getAliasForEntityClass(Class<? extends Entity> clazz) {
return clazz.getCanonicalName();
}
}
interface Entity {
Long getId();
}
interface Textable {
String getText();
}
템플릿 <T extends Entity & Textable>
및 <T extends Textable & Entity>
을 의미
public class TestGeneric {
EntityManager entityManager = new EntityManager();
public <T extends Textable & Entity> void doAction(T obj) {
entityManager.getAliasForEntityClass(obj.getClass());
}
}
class EntityManager {
public String getAliasForEntityClass(Class<? extends Entity> clazz) {
return clazz.getCanonicalName();
}
}
interface Entity {
Long getId();
}
interface Textable {
String getText();
}
나는 다음과 같은 오류를 받고 있어요 T Entity 및 Textable 인터페이스를 구현해야합니다. 이 예제에서 인터페이스의 위치가 중요한 이유는 무엇입니까?