[Practice] Effective Java practice summary

Creating and destroying objects

Article 1 is configured by considering instead of a static factory method

  • Static factory method has a name, it can accurately describe the object being returned.
  • You do not have to call creates a new object each time.
  • You can return to the original return type of any child class object.
  • More concise when creating a parameterized type instances, such as when call the constructor HashMap, use Map < String,List < String > m = HashMap.newInstance(), and Map < String,List < String > m > = new HashMap < String,List < String > >();

practice

  • JDKSource provides static methods: Collections.emptyList();(Note that the return of the List is not java.util.ArrayList but java.util.Collections.EmptyList inner class)
  • googleThe guavapackage offers Maps.newHashMap()and Lists.newArrayList()static methods create objects (returns java.util.ArrayList # ArrayList () and java.util.HashMap # HashMap ())

Reference:
"as Effective the Java" - reading summary

Guess you like

Origin www.cnblogs.com/z00377750/p/12425274.html