So I have this one line of code here:
LinkedList<Integer> p = (LinkedList) obj.c.clone();
I was wondering why do you need the (LinkedList)
part before obj.c.clone()
?
The answer is: You need type casting to get access to target class methods and fields.
Object
and LinkedList
is same type hierarchy, so you can cast, otherwise You would get ClassCastException
in Java.
For more information about type casting, See this link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With