• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding set to itself?  RSS feed

 
Maria Kowalczyk
Greenhorn
Posts: 15
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the code below doesn't work? I want to add a set to itself (just experimenting with Java). I declare a Set that holds any class that implements Set interface (by writing ? extends Set).



It won't compile giving:
java: no suitable method found for add(java.util.Set<capture#1 of ? extends java.util.Set>)
method java.util.Set.add(capture#2 of ? extends java.util.Set) is not applicable
(actual argument java.util.Set<capture#1 of ? extends java.util.Set> cannot be converted to capture#2 of ? extends java.util.Set by method invocation conversion)
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maria Kowalczyk wrote:Why the code below doesn't work? I want to add a set to itself (just experimenting with Java). I declare a Set that holds any class that implements Set interface (by writing ? extends Set).

No, you've defined a Set that holds an unknown type that extends Set, and Sets of unknown types cannot be updated.

What about just?

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!