Overview of Static Factory Methods

jvm-lukas.com 4 miesięcy temu

Short summary of Effective Java 3rd edition book - Chapter 2

Static factory method is not factory method. They are two different things.

Descriptive Method Names

Static factory methods can have names that describe the purpose of the method, making the code more readable and self-explanatory.

public static BigDecimal valueOf(long b){...}

in the case of simple objects, it is difficult to see the benefit of using static factory methods but for me, it is more natural to use valueOf than constructor

  • BigDecimal.valueOf(1) instead...
Idź do oryginalnego materiału