Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

# wildcards

sukruthi dandasi
Greenhorn
Posts: 9
hello.i have been learning about wildcards.i understood the concepts about bounded wildcards,lower and upper wildcards.but unable to implement in programs so can any one explain with example for upper and lower bound???

Stephan van Hulst
Bartender
Posts: 5813
61
• 1
Welcome to CodeRanch!

Can you show us what you have tried so far?

sukruthi dandasi
Greenhorn
Posts: 9
i have not tried as i am unable to understand how to do it,and questions seems to be very simple also one such program is Create a class for animals and extend the class for dog and cat.
Create an object for dogs and cats using bounded wildcards.
Print the number of dogs and cats along with the total number of animals.and its not homework .

Henry Wong
author
Marshal
Posts: 21122
78
sukruthi dandasi wrote:hello.i have been learning about wildcards.i understood the concepts about bounded wildcards,lower and upper wildcards.but unable to implement in programs so can any one explain with example for upper and lower bound???

sukruthi dandasi wrote:i have not tried as i am unable to understand how to do it,and questions seems to be very simple also one such program is Create a class for animals and extend the class for dog and cat.
Create an object for dogs and cats using bounded wildcards.
Print the number of dogs and cats along with the total number of animals.and its not homework .

You need to give us some clarity as what you mean by you understand the concept but don't understand how to do it. Perhaps you can elaborate on what you understand is the purpose of wildcards first?

Henry

sukruthi dandasi
Greenhorn
Posts: 9
i understood that ex: List<? extends Number> it means that it can list of number or any of its sub classes and List<? super Integer> that it matches list of integers and any type that super type of Integer.

Henry Wong
author
Marshal
Posts: 21122
78
• 1
sukruthi dandasi wrote:i understood that ex: List<? extends Number> it means that it can list of number or any of its sub classes

Slight clarification -- you probably understood it correctly, but from your wording, we should be sure.... A List<? extends Number> may be a List<Number> or List<Integer> or some other List of a subtype of Number. And the compiler does not know what generic type of the list actually is. It is *not* a list whose generic type is for Number and it subtypes. If you want a list that can hold any Number or subtypes, you do that with a List<Number> (no wildcards needed).

Anyway, can you tell us a bit on what you are confused with? Some of the reasons that is preventing you from implementing code?

Henry

sukruthi dandasi
Greenhorn
Posts: 9
I am unable to understand where and how to implement it.in above method program i.e to know total number of cats and dogs