Java 什么是「;“总合同”;方法论

Java 什么是「;“总合同”;方法论,java,Java,我在这里查看DataInputStream的java文档: 我想看看它的方法是什么,所以我看了一下readBoolean(),readByte(),readChar()等的描述 这些描述大致如下: 参见DataInput的readBoolean方法的通用合同 在扩展的解释中 public final boolean readBoolean() throws IOException See the general contract of the

我在这里查看
DataInputStream
的java文档:

我想看看它的方法是什么,所以我看了一下
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

我在哪里可以“看到”这些方法的通用合同?什么是一种方法的通用合同?

它只是意味着的文档包含更多细节。该文件特别指出:

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

因此,您应该期望
DataInputStream.readBoolean
以这种方式运行。

基类中方法的一般约定必须是所有扩展类中方法约定的基础。它是通用的,因为它一般适用于基类及其派生类的整个体裁。不管派生类可能添加到方法契约中的其他术语如何,它必须始终保持一般契约


显式通用契约是在基类的方法文档中给出的。

基于@JonSkeet的回答,“通用契约”通常描述附在接口方法上的文档,以一般方式描述方法的实现应如何运行或,基类方法的文档,该文档描述了该方法的重写行为。当有人编写一个特定的实现或重写时,他们可以只说“参见总合同”,而不是复制所有这些信息。