• Post Reply Bookmark Topic Watch Topic
  • New Topic

Wildcards  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a question related to Wildcards. Are the wildcards <?> and <? extends Object> only limit the user from Calling add()? Is there any other usage of these wildcards?

Regards,
Kashif
 
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add()? What are you talking about?
 
Kashif Nazar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry I could not define my question well. Please have a look at the following code;


 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't List an interface?
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//THIS THROWS A COMPILE TIME ERROR. IS THERE ANY OTHER FUNCTION THAT IS NOT ALLOWED BY THE COMPILER?


Instead of memorizing which methods causes a compiler error, when you do certain things, it may be a better to understand why it is a compile error to call the add() method under that condition.

After all, it is a compile error, when you try to call any method with invalid parameters, so why is the add() method different? That it requires that you memorize it?

Henry
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a look at the Java™ Tutorials section about generics would be helpful. Also Google for Angelika Langer Java generics FAQ.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!