wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics Again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics Again" Watch "Generics Again" New topic
Author

Generics Again

Costa lamona
Ranch Hand

Joined: Sep 24, 2006
Posts: 102
Hi, I thought that I have finished with Generics but, It is going again !!


This code does not compile with error message like this

incompatible types
found: Object
required: T
for (T t: input)


Why this error ?, specially that
<? super T> means any T or super type of it.
and if you replaced <? super T> with <? extends T>, It compiles.


SCJP 5
Dan Polak
Ranch Hand

Joined: Nov 06, 2006
Posts: 32
Of course it is not possible

What will happen when I run your methot like this

List<Integer> i = backwords(new ArrayList<Object>());

???


<a href="http://www.dantheman.pl" target="_blank" rel="nofollow">http://www.dantheman.pl</a>
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

the parameter input is of type <? super T>
but in the for loop it is used as type <T>.

You cannot cast from <? super T> to <T>.

Here a variation of yours included, method foo:


Yours,
Bu.


all events occur in real time
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics Again