Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures - Retired Getting There Class Review

Does the Date constructor return something?

The parameter passed in the video for the Treet constructor include new Date(). Is the Date constructor returning something? Don't we need to create the instance first ?

2 Answers

Wairton Rebouças
Wairton Rebouças
8,225 Points

"Don't we need to create the instance first ?" That's exactly what new Date() does, it creates a new instance.

the value will be stored on mCreationDate property

Thank You

Trevor Bye
Trevor Bye
4,474 Points

Here's a more detailed answer, as I had the exact same question. The basic idea is, you can do something like new Date(); if you only need that object reference once, but you wouldn't be able to use that object again after that since it wasn't assigned to anything. So if someone wanted to, they could make their code really messy by constantly calling new Date(); to fetch the current date, rather than setting it to a variable as Date date = new Date();.

https://community.oracle.com/thread/3561210?start=0&tstart=0