+ 2

Reference Types

Working my way through the classes module and have just got to references. So far to set up a new object it's been Person j = new Person() On this references section it simply starts with Person j; Is there a logical reason for this as currently it is a little frustrating trying to remember this variation when it does not seem necessary.

10th Nov 2017, 3:44 PM
David Wyness
David Wyness - avatar
2 odpowiedzi
+ 4
It creates the reference without having to actually create the object yet. This can be helpful in certain ways, but if you forget to do the things you're suppose to, you can run into the issue of null pointers or something taking up resources when it isn't even being used and may not even get used.
10th Nov 2017, 4:25 PM
AgentSmith
+ 1
Ok thanks for your help, that makes more sense now.
10th Nov 2017, 4:30 PM
David Wyness
David Wyness - avatar