Java Java Data Structures Getting There Type Casting

Chris Rubio
Chris Rubio
1,643 Points

Minute 1:30 HELPPP please

OK so on minute 1:30 he created the new treet and gave it inside the parameter @craig.., and then "Example text"..., and then new Date() ......ok so why after he created it on minute 1:30 does the date not show up? and where is "treet : " coming from ?

2 Answers

Abdullah Alosaimi
PLUS
Abdullah Alosaimi
Courses Plus Student 2,277 Points

That is determined by the toString() method. Take a look at his implementation of this method on previous videos. You can override this method with your own code and decide how the object will be printed as a string.

Chris Rubio
Chris Rubio
1,643 Points

I dont understand? why did he say new Date () and date did come up ? so is the compiler disregard the constructor ?

Abdullah Alosaimi
PLUS
Abdullah Alosaimi
Courses Plus Student 2,277 Points

Every time you create an object the REPL will call toString() method to show you information about the newly created object. You can define this method however you like. He decided not to print the Date.

Here is his code. You can change it and make the REPL print the Date.

public String toString(){
return "Treet: \"" + mDescription + "\" - @" + mAuthor;
}

Good Luck!