File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Problem in Generics" Watch "Problem in Generics" New topic
Author

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
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

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)
{
list.add(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: http://aspose.com/file-tools
 
subject: Problem in Generics
 
Similar Threads
GENERICS
Generics <?>
Generics
Generics
Generics