• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Utility Classes : final keword for utility classes

 
hemant Budhewar BamniBk
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is it good to have Utility classes as final?

and why?
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Utility classes are generally a bunch of static methods. Considering this, where does the final keyword come into the picture? What are you trying to do?
 
hemant Budhewar BamniBk
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Utility classes are generally a bunch of static methods. Considering this, where does the final keyword come into the picture? What are you trying to do?


Yes you are right, but
Is it mandatory for all Utility classes to have static methods?


 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.
It is not mandatory ! You can very well have a utility class with non static methods.

You still haven't answered my original question. Why do you want to make it final. What are you trying to do?
 
hemant Budhewar BamniBk
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:No.
It is not mandatory ! You can very well have a utility class with non static methods.

You still haven't answered my original question. Why do you want to make it final. What are you trying to do?



As we can have a utility class with non static methods, so anybody can override and change the behavior in the same application in a new utility method.

And there might be confusion for new developers while using such methods, as same name is there.

I would like to use them as like contentment.

 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you like the final keyword rather than static

 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your utility class has a private constructor only, to prevent instantiation, final would be a good idea, because it is impossible to extend from anyway.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic