接口中的 JML 规范和实现 class
JML specification in the interface and the implementing class
我对 java 有点陌生,所以在编程时我注意到我必须为我的子程序提供 JML 注释。当我使用面向对象的编程时,我注意到接口的使用,并且我必须使用 JML 规范在那里声明方法,问题是,当我完成接口后,我现在在 class 实现接口的人,当我再次声明 class 时,我是否也应该再次在 class 上方指定 JML 规范,还是可以省略它,因为它位于接口中?
JML验证工具应该知道这种情况,但需要查阅所用验证工具的文档。例如,对于 KeY(Java/JML 的交互式定理证明器),其行为在第二个 KeY book, which is similar to Leavens:
中得到了很好的描述
In JML, specification inheritance means that instance methods have to
obey the specifications of all methods they override. This, together
with the inheritance of invariants and history constraints, forces
subtypes to be behavioral subtypes [Dhara-Leavens96]
[Leavens-Naumann06] [Leavens06b].
因此您不需要重复 JML 契约,并且您的验证工具应该针对超类型中的契约验证覆盖的方法。
我对 java 有点陌生,所以在编程时我注意到我必须为我的子程序提供 JML 注释。当我使用面向对象的编程时,我注意到接口的使用,并且我必须使用 JML 规范在那里声明方法,问题是,当我完成接口后,我现在在 class 实现接口的人,当我再次声明 class 时,我是否也应该再次在 class 上方指定 JML 规范,还是可以省略它,因为它位于接口中?
JML验证工具应该知道这种情况,但需要查阅所用验证工具的文档。例如,对于 KeY(Java/JML 的交互式定理证明器),其行为在第二个 KeY book, which is similar to Leavens:
中得到了很好的描述In JML, specification inheritance means that instance methods have to obey the specifications of all methods they override. This, together with the inheritance of invariants and history constraints, forces subtypes to be behavioral subtypes [Dhara-Leavens96] [Leavens-Naumann06] [Leavens06b].
因此您不需要重复 JML 契约,并且您的验证工具应该针对超类型中的契约验证覆盖的方法。