"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
/*
* Constructor. Only the Java Virtual Machine creates Class
* objects.
*/
private Class() {}
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Which is no possible if the constructor is private. But I agree with you that you should make your class final in that case. I think it's clearer then a private constructor.Stephan van Hulst wrote:I think it's good practice to always declare a class final, regardless of whether its constructors are private.
Unless of course you intend the class to be overridden.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Campbell Ritchie wrote:If you have a private constructor in a class, it is probably a good idea to mark that class final, so users are reminded of that.
Good point. I forgot that bit. And agree with Stephan van Hulst about the desirability of all classes being final.Paul Clapham wrote: . . . combination of private constructors and public constructors, . . .