<s>
In	O
the	O
Java	B-Language
programming	I-Language
language	I-Language
,	O
the	O
wildcard	B-Language
?	O
</s>
<s>
is	O
a	O
special	O
kind	O
of	O
type	O
argument	O
that	O
controls	O
the	O
type	B-Language
safety	I-Language
of	O
the	O
use	O
of	O
generic	B-Language
(	O
parameterized	O
)	O
types	O
.	O
</s>
<s>
It	O
can	O
be	O
used	O
in	O
variable	O
declarations	O
and	O
instantiations	O
as	O
well	O
as	O
in	O
method	O
definitions	O
,	O
but	O
not	O
in	O
the	O
definition	O
of	O
a	O
generic	B-Language
type	O
.	O
</s>
<s>
This	O
is	O
a	O
form	O
of	O
use-site	O
variance	O
annotation	O
,	O
in	O
contrast	O
with	O
the	O
definition-site	O
variance	O
annotations	O
found	O
in	O
C#	B-Application
and	O
Scala	B-Application
.	O
</s>
<s>
Unlike	O
arrays	O
(	O
which	O
are	O
covariant	O
in	O
Java	B-Language
)	O
,	O
different	O
instantiations	O
of	O
a	O
generic	B-Language
type	O
are	O
not	O
compatible	O
with	O
each	O
other	O
,	O
not	O
even	O
explicitly	O
:	O
With	O
the	O
declaration	O
Genericxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
)	O
subGeneric	O
.	O
</s>
<s>
This	O
incompatibility	O
may	O
be	O
softened	O
by	O
the	O
wildcard	B-Language
if	O
?	O
</s>
<s>
is	O
used	O
as	O
an	O
actual	O
type	O
parameter	O
:	O
Genericxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
is	O
a	O
supertype	O
of	O
all	O
parameterizarions	O
of	O
the	O
generic	B-Language
type	O
Generic	B-Language
.	O
</s>
<s>
This	O
allows	O
objects	O
of	O
type	O
Genericxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
.	O
</s>
<s>
Using	O
Generic	B-Language
<	O
?	O
</s>
<s>
Another	O
possibility	O
is	O
Generic	B-Language
<	O
?	O
</s>
<s>
In	O
the	O
body	O
of	O
a	O
generic	B-Language
unit	O
,	O
the	O
(	O
formal	O
)	O
type	O
parameter	O
is	O
handled	O
like	O
its	O
upper	O
bound	O
(	O
expressed	O
with	O
extends	O
;	O
Object	O
if	O
not	O
constrained	O
)	O
.	O
</s>
<s>
In	O
the	O
other	O
direction	O
,	O
the	O
wildcard	B-Language
fits	O
no	O
other	O
type	O
,	O
not	O
even	O
Object	O
:	O
If	O
?	O
</s>
<s>
However	O
,	O
objects	O
of	O
the	O
unknown	O
type	O
can	O
be	O
read	O
from	O
the	O
generic	B-Language
object	O
and	O
assigned	O
to	O
a	O
variable	O
of	O
a	O
supertype	O
of	O
the	O
upperbound	O
.	O
</s>
<s>
A	O
bounded	O
wildcard	B-Language
is	O
one	O
with	O
either	O
an	O
upper	O
or	O
a	O
lower	O
inheritance	B-Language
constraint	O
.	O
</s>
<s>
The	O
bound	O
of	O
a	O
wildcard	B-Language
can	O
be	O
either	O
a	O
class	O
type	O
,	O
interface	B-Language
type	O
,	O
array	O
type	O
,	O
or	O
type	O
variable	O
.	O
</s>
<s>
Wildcards	B-Language
can	O
state	O
either	O
an	O
upper	O
bound	O
or	O
a	O
lower	O
bound	O
,	O
but	O
not	O
both	O
.	O
</s>
<s>
An	O
upper	O
bound	O
on	O
a	O
wildcard	B-Language
must	O
be	O
a	O
subtype	O
of	O
the	O
upper	O
bound	O
of	O
the	O
corresponding	O
type	O
parameter	O
declared	O
in	O
the	O
corresponding	O
generic	B-Language
type	O
.	O
</s>
<s>
An	O
example	O
of	O
a	O
wildcard	B-Language
that	O
explicitly	O
states	O
an	O
upper	O
bound	O
is	O
:	O
</s>
<s>
Generic	B-Language
<	O
?	O
</s>
<s>
This	O
reference	O
can	O
hold	O
any	O
parameterization	O
of	O
Generic	B-Language
whose	O
type	O
argument	O
is	O
a	O
subtype	O
of	O
SubtypeOfUpperBound	O
.	O
</s>
<s>
A	O
wildcard	B-Language
that	O
does	O
not	O
explicitly	O
state	O
an	O
upper	O
bound	O
is	O
effectively	O
the	O
same	O
as	O
one	O
that	O
has	O
the	O
constraint	O
extends	O
Object	O
,	O
since	O
all	O
reference	O
types	O
in	O
Java	B-Language
are	O
subtypes	O
of	O
Object	O
.	O
</s>
<s>
Generic	B-Language
<	O
?	O
</s>
<s>
can	O
hold	O
any	O
parameterization	O
of	O
Generic	B-Language
whose	O
any	O
type	O
argument	O
is	O
both	O
a	O
subtype	O
of	O
the	O
corresponding	O
type	O
parameter	O
's	O
upper	O
bound	O
and	O
a	O
supertype	O
of	O
SubtypeOfUpperBound	O
.	O
</s>
<s>
No	O
objects	O
may	O
be	O
created	O
with	O
a	O
wildcard	B-Language
type	O
argument	O
:	O
for	O
example	O
,	O
new	O
Genericxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1( 	O
)	O
is	O
forbidden	O
.	O
</s>
<s>
In	O
practice	O
,	O
this	O
is	O
unnecessary	O
because	O
if	O
one	O
wanted	O
to	O
create	O
an	O
object	O
that	O
was	O
assignable	O
to	O
a	O
variable	O
of	O
type	O
Genericxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
,	O
one	O
could	O
simply	O
use	O
any	O
arbitrary	O
type	O
(	O
that	O
falls	O
within	O
the	O
constraints	O
of	O
the	O
wildcard	B-Language
,	O
if	O
any	O
)	O
as	O
the	O
type	O
argument	O
.	O
</s>
<s>
However	O
,	O
new	O
ArrayListxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1( 	O
)	O
is	O
allowed	O
,	O
because	O
the	O
wildcard	B-Language
is	O
not	O
a	O
parameter	O
to	O
the	O
instantiated	O
type	O
ArrayList	O
.	O
</s>
<s>
In	O
an	O
array	O
creation	O
expression	O
,	O
the	O
component	O
type	O
of	O
the	O
array	O
must	O
be	O
reifiable	O
as	O
defined	O
by	O
the	O
Java	B-Language
Language	I-Language
Specification	I-Language
,	O
Section	O
4.7	O
.	O
</s>
<s>
This	O
entails	O
that	O
,	O
if	O
the	O
component	O
type	O
of	O
the	O
array	O
has	O
any	O
type	O
arguments	O
,	O
they	O
must	O
all	O
be	O
unbounded	O
wildcards	B-Language
(	O
wildcards	B-Language
consisting	O
of	O
only	O
a	O
?	O
)	O
</s>
<s>
For	O
example	O
,	O
new	O
Genericxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1[20]	O
is	O
not	O
.	O
</s>
<s>
This	O
will	O
generate	O
a	O
warning	O
since	O
it	O
is	O
less	O
type-safe	B-Language
(	O
see	O
Raw	B-Language
type	I-Language
)	O
.	O
</s>
<s>
In	O
the	O
Java	B-Language
Collections	O
Framework	O
,	O
the	O
class	O
Listxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
represents	O
an	O
ordered	O
collection	O
of	O
objects	O
of	O
type	O
MyClass	O
.	O
</s>
<s>
The	O
mnemonics	O
PECS	O
(	O
Producer	O
Extends	O
,	O
Consumer	O
Super	O
)	O
from	O
the	O
book	O
Effective	O
Java	B-Language
by	O
Joshua	O
Bloch	O
gives	O
an	O
easy	O
way	O
to	O
remember	O
when	O
to	O
use	O
wildcards	B-Language
(	O
corresponding	O
to	O
Covariance	O
and	O
Contravariance	O
)	O
in	O
Java	B-Language
.	O
</s>
