Jumat, 22 Oktober 2021

What is difference between ArrayList and ArrayList<?> in Java?- Raw Type vs Wildcard Example Tutorial

One of my readers asked me about the difference between ArrayList vs ArrayList< in Java?>, which was actually asked to him in a recent Java development interview. The key difference between them is that ArrayList is not using Generics while ArrayList is a generic ArrayList but they look very similar. If a method accepts ArrayList or ArrayList<?> as a parameter then it can accept any type of ArrayList like ArrayList of String, Integer, Date, or Object, but if you look closely you will find that one is raw type while the other is using an unbounded wildcard. What difference that could make? Well, that makes a significant difference because ArrayList with raw type is not type-safe but ArrayList<?> with the unbounded wildcard is type-safe.

Lorem ipsum is simply dummy text of the printing and typesetting industry.

Comments


EmoticonEmoticon

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)