What is a “general contract” method

I am looking at java docs for DataInputStream here: http://docs.oracle.com/javase/7/docs/api/java/io/DataInputStream.html

I want to see what his methods do, so I look at the descriptions of readBoolean() , readByte() , readChar() , etc.

All descriptions are something like:

See the general contract for the readBoolean DataInput method.

And in an extended explanation.

 public final boolean readBoolean() throws IOException See the general contract of the readBoolean method of DataInput. Bytes for this operation are read from the contained input stream. Specified by: readBoolean in interface DataInput Returns: the boolean value read. Throws: EOFException - if this input stream has reached the end. IOException - the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. See Also: FilterInputStream.in 

Where can I “see” the general contracts of these methods and what is the general contract of the method?

+5
source share
2 answers

It just means that the DataInput.readBoolean documentation contains more detailed information. In particular, this documentation states:

Reads one input byte and returns true if this byte is non-zero, false if this byte is zero. This method is suitable for reading a byte written by the writeBoolean method of the writeBoolean interface.

Therefore, you should expect DataInputStream.readBoolean to behave this way.

+4
source

A general method contract in a base class is one that should be the basis of method contracts in all expanding classes. The general thing is that it is applicable as a whole to the entire genre of the base class and all its derived classes. Regardless of other terms, derived classes can add to a method contract; it should always support a common contract.

An explicit generic contract is the one specified in the method documentation for the base class.

+1
source

Source: https://habr.com/ru/post/1210320/


All Articles