posted 1 month ago
Well, the most important aspects of making an immutable class are the ones Carey just gave. But depending who you ask, there is a third aspect that is usually also required: we must ensure that the class cannot be subclasses to make it mutable, either. Technically, Toad fulfills that requirement by having a private constructor, making it impossible to extend. As it happens, this also makes the class uninstantiable and pretty much useless, since no other method is provided to allow instantiation. Normally it would be more straightforward to simply mark the class final, and still allow it to be instantiated. A private constructor is fine, provided there is also some way to instantiate the class.
Note that, if Toad is a nested or inner class (where the outer class is not shown), then it's possible the outer class contains code that makes it instantiable and/or mutable. But assuming there's no outer class, then it is uninstantiable and immutable, and generally useless.