I have a class like this
@Getter
public class MyClass {
private Collection<String> headers;
public myConfig(DownloadRequest downloadRequest) {
this.headers = downloadRequest.getHeaders() == null ? new ArrayList() : downloadRequest.getHeaders();
}
}
When I run this it gives me java.lang.UnsupportedOperationException
.
As I use headers in another function and do getHeaders().clear()
, I get this error.
Return type of downloadRequest.getHeaders()
is Collection<String>
I am unable to figure out what I can cast the headers to.
I keep getting different Exceptions as I change my code, like UnsupportedOperationException
and java.lang.ClassCastException: java.util.Arrays$ArrayList incompatible with java.util.ArrayList
, when I change the code to something else, trying out other StackOverflow solutions like this - Why do I get an UnsupportedOperationException when trying to remove an element from a List?.
I have just started working on Java and have been working more on python and nodejs in the past.
Any help is appreciated.