File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wildcards

 
sukruthi dandasi
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4826
34
Chrome Netbeans IDE Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Can you show us what you have tried so far?
 
sukruthi dandasi
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20823
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20823
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic