The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problem in Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Problem in Generics" Watch "Problem in Generics" New topic

Problem in Generics

Poornima Sharma
Ranch Hand

Joined: Sep 09, 2008
Posts: 114
Hi friends,

in Generics what does it mean

<X extends Object>

I know what <? extends Object> mean but i cant understand the above.

Poornima Sharma
SCJP 6.0
ramesh maredu
Ranch Hand

Joined: Mar 15, 2008
Posts: 210

X extends Object, is syntax used to define boundaries, this kind of syntax is used in generic classes and methods.

See below code.

commented lines don't compile if you remove comment

SCJP 1.5 94%.
The greatest glory in living lies not in never falling, but in rising every time we fall.
Ankit Garg

Joined: Aug 03, 2008
Posts: 9463

Well both <? extends Object> and <X extends Object> mean the same thing to a certain extent. The only difference being this

with <X extends Object> you can declare references of type X.

<X extends Object> void method(List<X> list, X obj)

but you can't do the same with <? extends Object>

void method(List<? extends Object> list, ? obj) //compilation error.

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: Problem in Generics
It's not a secret anymore!