Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

K &B Erratum? Regarding generics  RSS feed

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given code :
import java.util.*;
2. public class Fruits {
3. public static void main(String [] args) {
4. Set c1 = new TreeSet();
5. Set o1 = new TreeSet();
6. bite(c1);
7. bite(o1);
8. }
9. // insert code here
10. }
11. class Citrus { }
12. class Orange extends Citrus { }

Which, inserted independently at line 9, will compile? (Choose all that apply.)

A). public static void bite(Set<?> s) { }
B). public static void bite(Set<Object> s) { }
C). public static void bite(Set<Citrus> s) { }
D). public static void bite(Set<? super Citrus> s) { }
E). public static void bite(Set<? super Orange> s) { }
F). public static void bite(Set<? extends Citrus> s) { }
G). Because of other errors in the code, none of these will compile.

Answer is : A,E,F
I know A is correct .
why E & F are correct ??


(edited topic to indicate K&B 5.0 erratum)
[ July 25, 2006: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use this:


Check out this past topic (about half way down)

Hopefully the K&B errata includes this by now
[ July 25, 2006: Message edited by: Barry Gaunt ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!