JML 不是 null 变体?

发布于 2024-10-06 03:06:06 字数 222 浏览 0 评论 0 原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

番薯 2024-10-13 03:06:06

关于 array_ 的元素?在每种情况下,他们拥有什么属性?

没有提及有关元素的内容。唯一可以保证的是 array_ 引用不为 null。

请注意 和 之间的区别

Object[] array = null;

,例如

Object[] array_ = { null };

or

Object[] array_ = { };

第一行将违反不变量,而后两行是允许的,因为 array_ 将指向一个实际数组(即使该数组可能只包含 null 元素或甚至根本没有元素)。


另一个区别是,在 invariant array_ != null; 方法中,array_ != null 必须仅在每个方法之后保存,而如果您使用 non_null< /code> pragma array_ != null 必须在整个程序的每个控制点保持不变。

regarding the elements of array_? What property holds for them in each case?

Nothing is said about the elements. The only thing that is guaranteed is that the array_ reference is not null.

Note the difference between

Object[] array = null;

and for instance

Object[] array_ = { null };

or

Object[] array_ = { };

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 the non_null pragma array_ != null must hold at every control point throughout the program.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文