由于在下面的代码中,R 扩展了 Appendable,我不应该能够在需要 R 的地方返回 Appendable 吗?
/**
* Produces an R, to which a T has been semantically appended,
* whatever that may mean for the given type.
*/
interface Appendable <R, T>
{
/**
* Append is not expected to modify this Appendable,
* but rather to return an R which is the result
* of the append.
*/
R append(T t);
}
interface PluralAppendable <R extends Appendable<R, T>, T>
extends Appendable<R, T>
{
default R append(T... els)
{
// Easier to debug than folding in a single statement
Appendable<R, T> result = this;
for(T t : els)
result = result.append(t);
/* Error: Incompatible types.
Required: R
Found: Appendable<R, T> */
return result;
}
}