什么是方法的"一般合同"

Zac*_*ooz 6 java

我在DataInputStream这里查看java文档:http://docs.oracle.com/javase/7/docs/api/java/io/DataInputStream.html

我期待看到它的方法做,我看的描述readBoolean(),readByte(),readChar()等.

这些描述都是这样的:

请参阅DataInput的readBoolean方法的常规协定.

并在扩展的解释中.

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
Run Code Online (Sandbox Code Playgroud)

我在哪里可以"看到"这些方法的一般合同以及方法的一般合同是什么?

Jon*_*eet 4

这只是意味着文档DataInput.readBoolean包含更多详细信息。该文件特别指出:

true读取一个输入字节,如果该字节非零则返回,false如果该字节为零则返回。该方法适合读取writeBoolean接口方法写入的字节DataOutput

所以你应该预料DataInputStream.readBoolean到会有这样的行为。