1. Form
The code copy is as follows:
public static Boolean valueOf(boolean b) {
return b ? Boolean.TRUE : Boolean.FALSE;
}
2. Advantages:
Can have a name
You do not have to create a new object, you can return an existing object
You can return objects of subclass type (example: java.util.Collections)
Make the parameterized code shorter (example: change new HashMap<String,List<String>>() to HashMap.newInstance() )
3. Disadvantages: It cannot be subclassed and cannot be recognized by IDE tools.
4. Common names: valueOf/of; getInstance(Singleton); newInstance; getType (used for different classes); newType