简体   繁体   中英

What is the “general contract” of a method

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

I'm looking to see what its methods do so I look at the descriptions of readBoolean() , readByte() , readChar() etc.

The descriptions are all something along the lines of:

See the general contract of the readBoolean method of DataInput.

And in the 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 a general contract of a method?

It just means that the documentation of DataInput.readBoolean contains more detail. In particular, that documentation states:

Reads one input byte and returns true if that byte is nonzero, false if that byte is zero. This method is suitable for reading the byte written by the writeBoolean method of interface DataOutput .

So you should expect DataInputStream.readBoolean to behave that way.

A general contract of a method in a base class is one that must be the basis of the contracts of the method in all extending classes. It is general in that it applies generally to the whole genre of the base class and all its derived classes. Regardless of other terms derived classes may add to the method's contract, it must always keep the general contract.

An explicit general contract is one that's given in the method documentation for the base class.

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