I have a java class which has only static methods and fields, so I don't want any object to be created for that. I can acheive this in two ways,
- make class abstarct.
- use private constructor.
Which of the two is better way?
I have a java class which has only static methods and fields, so I don't want any object to be created for that. I can acheive this in two ways,
Which of the two is better way?
You should go with
private
constructor.If your class is abstract, it can be extended and objects can be created. As per my understanding from the question, what you want is non instantiable class.
from Item 4 of Effective java :