나는 다음과 같은 자바 코드가 : 그 같은 수의 매개 변수가 있어야합니다 슈퍼 클래스의 서브 클래스를 의미합니까 ... "생성자 지정된 형태에 적용 할 수 없습니다"생성자를 주어진 유형에 적용 할 수 없습니까?
public class WeirdList {
/** The empty sequence of integers. */
/*ERROR LINE */ public static final WeirdList EMPTY = new WeirdList.EmptyList();
/** A new WeirdList whose head is HEAD and tail is TAIL. */
public WeirdList(int head, WeirdList tail) {
headActual = head;
tailActual = tail;
}
/** Returns the number of elements in the sequence that
* starts with THIS. */
public int length() {
return 1 + this.tailActual.length();
}
/** Apply FUNC.apply to every element of THIS WeirdList in
* sequence, and return a WeirdList of the resulting values. */
public WeirdList map(IntUnaryFunction func) {
return new WeirdList(func.apply(this.headActual), this.tailActual.map(func));
}
/** Print the contents of THIS WeirdList on the standard output
* (on one line, each followed by a blank). Does not print
* an end-of-line. */
public void print() {
System.out.println(this.headActual);
this.tailActual.print();
}
private int headActual;
private WeirdList tailActual;
private static class EmptyList extends WeirdList {
public int length() {
return 0;
}
public EmptyList map(IntUnaryFunction func) {
return new EmptyList();
}
public void print() {
return;
}
}
그리고 오류가 계속를 수퍼 클래스로 생성자에서? 나는 한 시간 동안 벽에 머리를 두드렸다.
'EmptyList' 내부 클래스는 생성자가 없습니다. _somehow_ _a_ 부모 클래스 생성자를 호출하는 데 필요한 생성자입니다. 기본 상위 생성자가 없기 때문에 내부 클래스 _must_는 _a_ 상위 생성자를 수동으로 호출합니다. 'WeirdList'의 생성자는'head'와'tail'의 타입이 다르며'EmptyList'에도 분명히없는 꼬리가 필요하다는 점에서 이상합니다. 나는'EmptyList'가'implement' 할 수있는'interface'를 사용하고 더 감각적 인 WeirdList 생성자를 사용하도록 제안 할 것입니다. – pickypg