Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a peer class in Java?

I came across the fact StringBuffer is called peer class of String. What is a peer class?

like image 701
satheesh.droid Avatar asked Dec 30 '10 11:12

satheesh.droid


People also ask

What is a peer class?

The purpose of the abstract Peer class is to provide a common base class definition that can be shared by derived classes, such as PeerNearMe and PeerContact. It cannot be directly constructed, since it is abstract.

What does native peers mean?

A native peer is a native object to which a normal object delegates via native methods. Because a native peer is not a normal object, the garbage collector doesn't know about it and can't reclaim it when its Java peer is reclaimed.


1 Answers

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.

like image 129
Daniel Rikowski Avatar answered Sep 27 '22 03:09

Daniel Rikowski