我有以下密封接口(Java 15):
public sealed interface Animal permits Cat, Duck {
String makeSound();
}
该接口由 2 个类实现:
public final class Cat implements Animal {
@Override
public String makeSound() {
return "miau";
}
}
public non-sealed class Duck implements Animal {
@Override
public String makeSound() {
return "quack";
}
}
谁能告诉我和之间的final
区别non-sealed
?final
阻止我创建其他子类,但non-sealed
适用于什么行为Duck
?