Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the "general contract" of a method

Tags:

java

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?

like image 814
Zachooz Avatar asked Jan 03 '15 18:01

Zachooz


2 Answers

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.

like image 52
Jon Skeet Avatar answered Oct 25 '22 02:10

Jon Skeet


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.

like image 1
Simon Towler Avatar answered Oct 25 '22 01:10

Simon Towler