Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Adding set to itself?

 
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)
 
Bartender
Posts: 10777
71
Hibernate Eclipse IDE 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
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic