Photo by Ilkka Kärkkäinen on Unsplash

Unbounded Wildcards

LIU YONGLIANG

--

I discussed generics and bounded wildcards in the below article.

While I covered most of the basics about generics and wildcards, there are still areas requiring further attention and discussion. In this article, I would like to pen down some subtleties with regard to unbounded wildcards.

Motivation

Some common questions around this topic are:
1. What is the difference between List<?> and List<Object>

2. What is the difference between List<?> and List<? extends Object>

3. Can return types be ? or List<?>

p.s. While I used List<?> in my examples, I am referring to all possible generic classes, such as custom a generic class named ImmutableList<?>.

Question 1

What is the difference between `List<?>` and `List<Object>` ?

When we talk about wildcards and generics, our focus is always on type and type safety. The purpose of having these implementations is to allow for…

--

--

LIU YONGLIANG
LIU YONGLIANG

Written by LIU YONGLIANG

Computer Science Student @ National University of Singapore. Connect with me @ https://www.linkedin.com/in/-yong-/

No responses yet