In the new date package in Java 8, we changed from using "new Date()" to "LocalDate.of()".
Date d = new Date(year, month, dayOfMonth); //Old way
LocalDate d2 = LocalDate.of(year, month, dayOfMonth); //new way
When you want a new object you usually use the new
keyword. This is an intuitive way to create a new object.
Sometimes, when you need a singleton with delayed initialization you can use a static method to get the instance. In this case you must call it getInstance()
so developers know what to expect.
This new syntax makes the code less intuitive. It forces you to learn how to deal with specific objects instead of simply using them.
Are there any good reasons under the hood for this change?