Java – why can’t we create an instance of the collections class (not the collection interface)?
•
Java
Collections is a public class, and then we can call its implicit default constructor It has no private constructor, which prevents object creation or forces the use of static factory methods When I instantiate as a new collection (), I get the error "constructor invisible" Anyway, why can't we have Java util. An instance of the collections class? thank you.
Solution
Start with documentation: "this class only contains static methods that operate on or return collections."
In other words, collections are just collections of methods An example of it makes no sense It's like mathematical functions: you don't have mathematical examples, you just need to use these functions
It is not an interface because it has specific methods
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码