• Post Reply Bookmark Topic Watch Topic
  • New Topic

reference problem  RSS feed

 
harsh garg
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if this is Strong Reference in java

StringBuffer sb=new StringBuffer();


Then what is the type of this reference:

Container c=getContentPane();//It is used in Swing....
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still a strong reference, but with a widened reference type.
 
harsh garg
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Still a strong reference, but with a widened reference type.




how this possible,i do not understand?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The strength of a reference determines how the garbage collector will treat the reference. A strong reference, like the ones you gave, will prevent the garbage collection of an object, whereas weak references will not. See java.lang.ref for more information.

The Container example you gave is just widening. The actual class of the object may be a JPanel, or a Window, or any class that is a direct or indirect sub class of Container. It can even be Container itself. It's similar to the following:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!