첫 번째 버전 :이 프로그램의 v1은 컴파일되지만 v2는 컴파일되지 않습니다. 디자인에 의한 것인가? 그렇다면 왜?
public interface DeepCopyable<T>
{
T deepCopy();
}
public interface Statement extends DeepCopyable<Statement>
{
}
public interface Expression
{
Expression deepCopy(); // forgot I have an interface for this
}
public class Invocation implements Expression, Statement
{
public final String Field;
public Invocation(String field)
{
Field = field;
}
public Invocation deepCopy()
{
return new Invocation(Field);
}
}
두 번째 버전, 표현의 인터페이스 업데이트 :
public interface Expression extends DeepCopyable<Expression>
{
}
을하지만 지금은 내가이 오류 메시지를 이해할 수
Error: C:\temp\Invocation.java:1: DeepCopyable cannot be inherited with different arguments: <Expression> and <Statement>
컴파일 오류를 얻을 일반적으로 수익 유형은 불변합니다. 그러나 반환 유형 A와 B를 사용하여 동일한 인터페이스를 두 번 상속하고 구현 메서드가 C를 반환하는 경우 C가 공분산이고 A와 B는 안전하지 않아야합니다.
컴파일 오류가 없기 때문에 두 번째 버전의 전체 코드를 게시 할 수 있습니까? – ka3ak