JML 不是 null 变体?
我有一个 JML 问题。 有什么区别
/*@ invariant array_ != null; */
和将其声明为
protected /*@ non_null */ Object[] array_;
关于 array_ 的元素 ?在每种情况下,他们拥有什么财产?
提前致谢。
i have a JML questions. what is the difference between
/*@ invariant array_ != null; */
and declaring it as
protected /*@ non_null */ Object[] array_;
regarding the elements of array_? What property holds for them in each case?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有提及有关元素的内容。唯一可以保证的是
array_
引用不为 null。请注意 和 之间的区别
,例如
or
第一行将违反不变量,而后两行是允许的,因为
array_
将指向一个实际数组(即使该数组可能只包含 null 元素或甚至根本没有元素)。另一个区别是,在
invariant array_ != null;
方法中,array_ != null
必须仅在每个方法之后保存,而如果您使用non_null< /code> pragma
array_ != null
必须在整个程序的每个控制点保持不变。Nothing is said about the elements. The only thing that is guaranteed is that the
array_
reference is not null.Note the difference between
and for instance
or
The first line would violate the invariant, while the latter two would be allowed, as
array_
would point to an actual array (even though this array may only contain null elements or even no elements at all).Another difference is that in the
invariant array_ != null;
approach,array_ != null
must only hold before after each method, while if you use thenon_null
pragmaarray_ != null
must hold at every control point throughout the program.