• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generics ...Please Help.......

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public static <E extends Number> List<? super E> check(List<E> list)
{
return null;
}

public static void main(String... a)
{
//Line 1
//Line 2

output = check(input);
}


List<Integer> input = null;
List<Integer> output = null; // Case 1

OR

List<Number> input = null;
List<Number> output = null; // Case 2

Why inserting the above for Line 1 & Line 2 does not work......?
Here my doubt is that in case of return typ for the above function

List<? super E> if I take the input as above say case 1 then E is Integer

so the return type becomes List<? super Integer>
so here if I return List<Integer> output; then it should also work..

I am really confused with List<? super Integer>
If I am correct it means List of Integer/List of anything that is super class of Integer...
Please help............
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

It seems that you are using an old copy of the SCJP book by K&B.

You can check the below threads to find the solution for your query.

https://coderanch.com/t/269133/java-programmer-SCJP/certification/Generics

https://coderanch.com/t/268612/java-programmer-SCJP/certification/SCJP-Chapter

Hope this helps.

Kind Regards
Kris
 
kapil kumar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Kris..

public static <E extends Number> List<? super E> check(List<E> list)

Here I am having doubt in List<? super E>
Suppose if I take E as Integer then the above declaration becomes
List<? super Integer> which means I can return anything that is Integer
or a supertype of Integer .....(Number/Object)

so why it doesn't work..?

Please reply.......
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic