gpt4 book ai didi

java - 方法的 "general contract"是什么

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:17:18 24 4
gpt4 key购买 nike

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

我想看看它的方法是做什么的,所以我查看了 readBoolean() 的描述, readByte() , readChar()等等

描述都是这样的:

See the general contract of the readBoolean method of DataInput.

并在扩展说明中。

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

从哪里可以“看到”这些方法的总契约,什么是方法的总契约?

最佳答案

这只是意味着DataInput.readBoolean的文档包含更多细节。该文档特别指出:

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.

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

关于java - 方法的 "general contract"是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27758341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com