I am reading the Effective Java
by Joshua Bloch and I have question about Item1 Static Factory Method
.
Quote[Bloch, p.7]
Interfaces cant have static methods,
so by convention, static factory
methods for an interface named Type
are put in non-instantiable class
named Types. For example, the Java
Collections Framework, provide
unmodifiable collections, synchronized
collections, and the like. Nearly all
of these implementations are export
via static factory methods in one
noninstantiable class
(java.util.Collections). The classes
of the returned objects are all
non-public.
Ok. When look at the sources code, I see java.util.Collection
interface and java.util.Collections
class with private constructor (non-instantiable class). and I see that the non-instantiable class Collections has all static methods, just like what Bloch said. But i fail to see the connection between the two classes as Bloch said
Interfaces cant have static methods, so by convention, static factory methods for an interface named Type are put in non-instantiable class named Types.
Can anyone point out the obvious to me?
what is it mean when he said
The classes of the returned objects are all non-public
Here is where I obtain the java sources: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/Collection.java?av=f
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…