Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finallizer() & clone method are protected

 
Manish Thapliyal
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why the finallizer() & clone method are protected . why not public or private
Please explain.
 
amitabh mehra
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manish, you can check this thread for the same:why is finalize() protected
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some people would suggest avoiding clone() altogether.

An old thread will give some more detail on clone().

The default implementation will throw an exception - no need for anyone to call it. If you override it, you can make it public.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bill Shirley:
Some people would suggest avoiding clone() altogether


... and others would suggest avoiding finalize() altogether, too.

Both finalize() and clone() are relics from the very earliest days of Java. They aren't as well thought-out as later features. Luckily, extremely few programs really need finalize() [use weak or phantom references instead], and few need clone().

I consider cloning of arrays to be a special case. It's the most efficient way to copy a whole array, and there are no confusions with how to override the array-cloning method, because you can't.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic