Java 中的对等类是什么?
我发现 StringBuffer
被称为 String
的对等类。什么是同侪班级?
I came across the fact StringBuffer
is called peer class of String
. What is a peer class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先:您必须小心使用术语“对等类”,因为在 Java 中它具有独特的含义:对等类是本机类的“接口”。 (例如 C++ 类)(有关详细信息,请参阅其他答案)
在您的情况下,该术语似乎不在特定上下文中使用!
无论谁将
StringBuffer
称为String
的对等类,显然都在一般意义上使用了该词。在某种程度上,StringBuffer
和String
是相关的,并且它们都可以用于类似的目的。我想在某些用例中,他们可以被视为更广泛意义上的同行。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 toString
obviously used that word in a general sense. In a wayStringBuffer
andString
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.据我所知,编写对等类是为了将代码与本机代码连接起来。
请参阅这篇文章,http://javapapers.com/core-java/java-peer-类/。
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/.