方法的“通用契约”是什么?

6
我正在查看这里的Java文档:http://docs.oracle.com/javase/7/docs/api/java/io/DataInputStream.html 我想知道它的方法是做什么的,所以我查看了, , 等方法的描述。
这些描述都大致如下:
请参阅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

这些方法的总体合约在哪里可以找到?什么是一个方法的总体合约?


4
在@JonSkeet的答案基础上,“General contract”通常指附加到接口方法上的文件,描述了实现该方法应该如何行为或者描述一个基类方法的文档,说明其重写应该如何行为。当某人编写特定的实现或重写时,他们只需说“参见一般契约”而不是复制所有信息。 - Solomon Slow
2个回答

4
这只是意味着DataInput.readBoolean的文档包含更多细节。特别是,该文档说明:

读取一个输入字节并返回true(如果该字节为非零),false(如果该字节为零)。该方法适用于读取接口DataOutputwriteBoolean方法写入的字节。

因此,您应该期望DataInputStream.readBoolean的行为方式如上所述。


1

基类中的方法的一般契约是所有扩展类方法契约的基础。它是“通用”的,因为它通常适用于基类及其所有派生类的整个类型。无论其他派生类可能添加到该方法的契约的条款如何,它必须始终保持通用契约。

一个明确的通用契约是在基类的方法文档中给出的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接