• 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 Error

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I write the below code

package com.scjp.ch7;

import java.util.ArrayList;
import java.util.List;

public class GenericTest {

/**
* @param args
*/
public static <E extends Number> List <? super E> process (List<E> nums) {
return null;
}

public static void main(String[] args) {
// TODO Auto-generated method stub
List<Integer> input = new ArrayList<Integer>();
List<Integer> output = new ArrayList<Integer>();

output = process(input);
}
}

It gives me this error.

[root@localhost ~]# javac GenericTest.java
GenericTest.java:22: incompatible types
found : java.util.List<capture of ? super java.lang.Integer>
required: java.util.List<java.lang.Integer>
output = process(input);
^
1 error

According to my study book it should work and when i eyeball it looks correct too. Is my book wrong? (for those interested pg. 634 qu.16 of Sun Certified Programmer for Java 5.

regards
Harry
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the K & B Errata given by the link at the top of this forum.
reply
    Bookmark Topic Watch Topic
  • New Topic