What are static factory methods?

前端 未结 14 738
粉色の甜心
粉色の甜心 2020-11-22 06:08

What\'s a \"static factory\" method?

14条回答
  •  清酒与你
    2020-11-22 06:39

    • have names, unlike constructors, which can clarify code.
    • do not need to create a new object upon each invocation - objects can be cached and reused, if necessary.
    • can return a subtype of their return type - in particular, can return an object whose implementation class is unknown to the caller. This is a very valuable and widely used feature in many frameworks which use interfaces as the return type of static factory methods.

    fromhttp://www.javapractices.com/topic/TopicAction.do?Id=21

提交回复
热议问题