What are static factory methods?

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

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

14条回答
  •  醉话见心
    2020-11-22 06:48

    Java implementation contains utilities classes java.util.Arrays and java.util.Collections both of them contains static factory methods, examples of it and how to use :

    • Arrays.asList("1","2","3")

    • Collections.synchronizedList(..), Collections.emptyList(), Collections.unmodifiableList(...) (Only some examples, could check javadocs for mor methods examples https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html)

    Also java.lang.String class have such static factory methods:

    • String.format(...), String.valueOf(..), String.copyValueOf(...)

提交回复
热议问题