Forums Register Login

What is the difference between these two List intiializations?

+Pie Number of slices to send: Send
What is the difference between these two Lists?

and

I can use the .add method on each right?

I do not understand the difference between the two, or what kind of functionality I gain or lose when making the choice.
Can someone help me or direct me to some reading that will enlighten me?

Thanks
1
+Pie Number of slices to send: Send
The first one is an empty reference - a null reference if you will. So no, you can't call orderList.add(order); on it because you would get a NullPointerException, (unless you assign an object to it between the variable definition and method call).

The second one actually creates an Object of a suitable, concrete implementation of List, and so can have a method called on it without an error occurring.
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 596 times.
Similar Threads
Hibernate 3 Annotations
Using Generics method parameters and wildcards
Jsp Document vs Jsp Page - clarification
about isThreadSafe
Type Safety
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:34:08.