Collections is a public class, then we can call its implicit default constructor. It doesn't have private constructor, which would prevent object creation or force to have static factory method. When I do instantiate as new Collections(), i get error as "Constructor not visible". In short why can't we have instance of java.util.Collections class? Thanks.
3
votes
2 Answers
9
votes
From the documentation: "This class consists exclusively of static methods that operate on or return collections."
In other words, Collections is just a collection of methods. An instance of it would not make any sense. It is just like the math functions: You don't have an instance of math, you just use the functions.
It is not an interface as it has concrete methods.
4
votes
The reason for the "Constructor not visible" message is that the constructor is private (line 73), or at least according to this site . And as others already stated, what would you do with an instance of this class as it only contains static methods
// Suppresses default constructor, ensuring non-instantiability.
private Collections() {
}
java.util.Collectionsclass does have a private constructor! - home