【发布时间】:2018-03-13 04:16:16
【问题描述】:
考虑以下示例:
open class A { // This class is from the SDK and cannot be modified in anyway.
open func aFunc() {}
}
以下是我自己的课程,我需要打开该课程以供其他人覆盖。但该方法不应该可用于覆盖。
open class B : A { // This has to be open for others to override.
override open func aFunc() {} // I need to make this **final** somehow so the subclasses cannot override this.
}
是否可以在类B final 中标记aFunc() 方法?
我尝试添加 final 关键字,但出现编译器错误提示
实例方法不能同时声明为'final'和'open'
如果我删除 open 关键字,则会出现编译器错误提示
重写实例方法必须与它的声明一样可访问 覆盖
【问题讨论】: