4

以下是合法的(即我可以编译它)并在启用预览功能的 Java 15 中工作(在 eclipse 2020-09 中)

public sealed interface Quantity<T> permits QuantityImpl { }
public record QuantityImpl<T extends Number>(T value) implements Quantity<T> { }

public class Play {
    public static void main(String[] args) {
        Quantity<Float> q = new QuantityImpl<>(3.0f);
        System.out.println(q instanceof Quantity);
    }
}

Quantity.java但是,日食在抱怨... permits QuantityImpl。当悬停在QuantityImpl一个可以阅读:

Permitted type QuantityImpl does not declare Quantity<T> as direct super interface

即使它编译,这是一个有效的投诉还是 eclipse 中的错误?

4

0 回答 0