+ 2

Why no "new" keyword needed when creating object in LocalDateTime in Java?

Hi quck question. Why no "new" keyword needed when creating object in LocalDateTime? exp: LocalDateTime rightNow = LocalDateTime.now(); System.out.println("current datetime : " + rightNow); But if we create an new Object of the class or object of StringBuilder we need to use new keyword exp ClassName refName = new Classname(); or StringBuilder sb = new StringBuilder(); Thnaks in advance

7th Dec 2017, 12:05 PM
Roman
Roman - avatar
7 Respostas
7th Dec 2017, 7:42 PM
David Akhihiero
David Akhihiero - avatar
+ 8
LocalDateTime has a static method called now() that returns a LocalDateTime Object
7th Dec 2017, 3:43 PM
David Akhihiero
David Akhihiero - avatar
+ 5
You're welcome Roman
8th Dec 2017, 6:45 PM
David Akhihiero
David Akhihiero - avatar
+ 1
Thank you, but it didn't answer my question
7th Dec 2017, 4:13 PM
Roman
Roman - avatar
+ 1
Yerucham thank you, understood!!!
7th Dec 2017, 9:06 PM
Roman
Roman - avatar
+ 1
new is a special keyword and when we use ' new' it do the following 3 steps 1. reads the class 2.invokes the constructors. 3.allocates the memory.
8th Dec 2017, 1:23 AM
smaky dub
smaky dub - avatar
+ 1
so localdatetime needs no new
8th Dec 2017, 1:24 AM
smaky dub
smaky dub - avatar