Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Ron McLeod
Paul Clapham
Tim Cooke
Devaka Cooray
Sheriffs:
Liutauras Vilda
paul wheaton
Rob Spoor
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Piet Souris
Mikalai Zaikin
Bartenders:
Carey Brown
Roland Mueller
Forum:
Programmer Certification (OCPJP)
Generics Question
temesgen kahsay
Greenhorn
Posts: 4
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi ranchers, i am new to post but i almost read the forum daily. and to come to my question,
why is the line commented as "This line" not working
import java.util.*; class Animal {} class Dog extends Animal {} class Cat extends Animal {} class generics4 { public void addAnimal(List<? super Dog> animals) { animals.add(new Dog()); animals.add(new Animal());//This line } public static void main(String[] args) { List<Animal> animals = new ArrayList<Animal>(); animals.add(new Dog()); animals.add(new Dog()); animals.add(new Cat()); generics4 doc = new generics4(); doc.addAnimal(animals); } }
Henry Wong
author
Posts: 23956
142
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You already asked this exact question yesterday. And it has already been answered.
https://coderanch.com/t/465227/Programmer-Certification-SCJP/certification/Why-not-working
Henry
Books:
Java Threads, 3rd Edition
,
Jini in a Nutshell
, and
Java Gems (contributor)
Hot dog! An advertiser loves us THIS much:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Generics.
Whats wrong with this code
Generics problem- why not taking Animal, Object and super of Dog
Doubt in generics
Generics Problem
More...