If I do add in the following code, I get a compile error. In the case of extends, it is an Upper Bounded Wildcard (? extends interface or class as a). If it is a class that inherits a, I think my code should succeed. But it failed and I don't know why.
Help
this is Error Message
'add(capture<? extends org.springframework.security.core.GrantedAuthority>)' in 'java.util.Set' cannot be applied to '(org.springframework.security.core.authority.SimpleGrantedAuthority)'
this is Error Code
Set<? extends GrantedAuthority> modifiedSet = new HashSet<>();
SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority(p.getValueAsString());
modifiedSet.add(simpleGrantedAuthority);
But again, inserting in a stream format like the one below is confusing because it works normally.
Set<? extends GrantedAuthority> authSet =
member.getAuthorities()
.stream()
.map(authority -> new
SimpleGrantedAuthority(authority.getAuthority()))
.collect(Collectors.toSet());