Reputation: 1520
I am trying to call setHeaders method of org.springframework.security.oauth2.client.token.AccessTokenRequest and not able to do it.
Class org.springframework.security.oauth2.client.token.AccessTokenRequest declares
void setHeaders(Map<? extends String, ? extends List<String>> headers);
Questions:
Since String is a final class in java, what purpose does it solve to say "? extends String" in the declaration.
How do I create my map and put entry in it. I have tried following
final Map<? extends String, ? extends List<String>> headers = accTknReq.getHeaders();
final List<String> lst1 = headers.get("MyHeader");
final ArrayList<String> lst2 = new ArrayList<>();
headers.put("MyHeader", lst1);
headers.put("MyHeader", lst2);
In both cases I get following compiler error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project : Compilation failure: Compilation failure:
[ERROR] :[33,24] method put in interface java.util.Map cannot be applied to given types; [ERROR] required: capture#1 of ? extends java.lang.String,capture#2 of ? extends java.util.List [ERROR] found: java.lang.String,java.util.List
Upvotes: 1
Views: 913
Reputation: 1180
For your second question, you can try something like the following to set headers.
final Map<String, List<String>> headers = new HashMap<>(accTknReq.getHeaders());
Upvotes: 3