Forums Register Login

Generics Again

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Of course it is not possible

What will happen when I run your methot like this

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

???
+Pie Number of slices to send: Send
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.
Tell me how it all turns out. Here is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 556 times.
Similar Threads
generics
generics question
Generics
Solution needed for Generics Question
Generics
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:18:48.