简体   繁体   中英

JML, accurate definition for invariants

Could someone give accurate meaning to the following invariants in Java Modelling Language pointing out the main difference between these?

  • public invariant
  • abstract function (private invariant)
  • representation invariant (private invariant)

Visibility modifiers are explained in the JML reference manual ; a short note on the visibility specifically of invariants is given in this section . The principle insight is that

The access modifier of an invariant affects which members , ie which fields and which (pure) methods, may be used in it , according to JML's usual visibility rules.

and

The access modifiers of invariants do not affect the obligations of methods and constructors to maintain and establish them . That is, all non-helper methods are expected to preserve invariants irrespective of the access modifiers of the invariants and the methods. For example, a public method must preserve private invariants as well as public ones.

That is, a public invariant may talk about public members and a private one about public, protected, package-visible and private members; and all methods have to establish all the class invariants.

I don't really know what you mean by "abstract function (private invariant)", there does not seem to be any hidden semantic meaning in the access modifiers, they're just access modifiers and nothing more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM