wood burning stoves 2.0*
The moose likes Java in General and the fly likes Utility Classes : final keword for utility classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Utility Classes : final keword for utility classes" Watch "Utility Classes : final keword for utility classes" New topic
Author

Utility Classes : final keword for utility classes

hemant Budhewar BamniBk
Ranch Hand

Joined: May 09, 2009
Posts: 33
Hi,
Is it good to have Utility classes as final?

and why?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10175
    
    8

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?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
hemant Budhewar BamniBk
Ranch Hand

Joined: May 09, 2009
Posts: 33
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

Joined: Jul 26, 2007
Posts: 10175
    
    8

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

Joined: May 09, 2009
Posts: 33
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

Joined: Jul 26, 2007
Posts: 10175
    
    8

Perhaps you like the final keyword rather than static

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Utility Classes : final keword for utility classes
 
Similar Threads
Which is the better approach
Library class
Way to force the methods to be implemented by user
client-side classes?
constructor private ?