aspose file tools*
The moose likes Java in General and the fly likes wildcards Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "wildcards" Watch "wildcards" New topic
Author

wildcards

sukruthi dandasi
Greenhorn

Joined: Jan 12, 2013
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

Joined: Sep 20, 2010
Posts: 3647
    
  16

Welcome to CodeRanch!

Can you show us what you have tried so far?
sukruthi dandasi
Greenhorn

Joined: Jan 12, 2013
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
Sheriff

Joined: Sep 28, 2004
Posts: 18847
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
sukruthi dandasi
Greenhorn

Joined: Jan 12, 2013
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
Sheriff

Joined: Sep 28, 2004
Posts: 18847
    
  40

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

Joined: Jan 12, 2013
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
 
wood burning stoves
 
subject: wildcards