Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What to do ??

 
Kumar Navin
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends,
I have to fulfill two conditions while defining the class-
1) I don't want my class to be extended.
2) I don't want anyone to instantiate my class.
How do I do that as a class cannot be abstract and final at the same time.
Thanks.

-Navin.
 
arnel nicolas
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about making the constructor of your class private.
 
Beny Na
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hehe..yes..making the contructor as private as Arnel said.

good reply Nicholas..
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and mark the class itself as final.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic