This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Utility Classes : final keword for utility classes

 
hemant Budhewar BamniBk
Ranch Hand
Posts: 33
  • 0
  • 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: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • 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
  • 0
  • 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: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • 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
  • 0
  • 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: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you like the final keyword rather than static

 
Campbell Ritchie
Sheriff
Pie
Posts: 47270
52
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic