問題描述
Java 中的對等類是什麼? (What is a peer class in Java?)
I came across the fact StringBuffer
is called peer class of String
. What is a peer class?
‑‑‑‑‑
參考解法
方法 1:
First of all: You have to be careful with the term "peer class", because in Java it has a distinct meaning: Peer classes are "interfaces" to native classes. (a C++ class for example) (See the other anwsers for details)
In your case the term seems not to be used in that specific context!
Whoever called StringBuffer
a peer class to String
obviously used that word in a general sense. In a way StringBuffer
and String
are related and both of them can be used for similar purposes. I guess in some use cases they could be considered peers in the broader sense of the word.
方法 2:
As I know, peer classes are written to connect the code with the native code. See this article, http://javapapers.com/core‑java/java‑peer‑class/.
(by satheesh.droid、Daniel Rikowski、Greenhorn)