Answer the question
In order to leave comments, you need to log in
Why doesn't the value type match?
Hello. I am writing a plugin for Jira, in the overridden override
method it is required that the method returns a type: List<IssueAction>
List
and IssueAction
these are interfaces.
I googled and found an example return value, it was like this:
return Lists.newArrayList(
new GenericMessageAction("Запись 1"),
new GenericMessageAction("Запись 2")
);
GenericMessageAction
- This is a class that implements the interface, a IssueAction
newArrayList
function from which com.google.common.collect.Lists
returns ArrayList
that implements the interface. List
GenericMessageAction
to the list, the method newArrayList
returns to me ArrayList<GenericMessageAction>
ArrayList<GenericMessageAction> list = Lists.newArrayList(
new GenericMessageAction("Запись 1"),
new GenericMessageAction("Запись 2")
);
return list;
List<IssueAction>
, I return ArrayList<GenericMessageAction>
where it ArrayList
implements List
and GenericMessageAction
implements IssueAction
, and that’s it List<IssueAction>
. Answer the question
In order to leave comments, you need to log in
Funny, this is the first time I've seen this happen. This is called invariance when ArrayList{GenericMessageAction} is not a child of List{IssueAction}. Made this way because of overwriting generics in java, problems due to absolute compatibility. If you don’t understand what I mean, it’s better to read the articles, it is detailed there.
in your case the solution would be to declare list. You're directly violating the solid by announcing as it is now.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question