I have a class with a generic type:
class MyClass<K extends InterfaceA & InterfaceB>{...}
Where InterfaceA
and InterfaceB
have methodA
and methodB
respectively. Both methods are of return type String
In this class there is List<K>
which I process in the following way:
public void setList(List<K> list){
Map<String,K> map = list
.stream()
.collect(Collectors.toMap(K::methodB, p -> p))
}
This fails silently and I believe this is just because the exception is not propagated. However, if I use K::methodA
everything works.
If I swap the interface declaration of K
as such:
class MyClass<K extends InterfaceB & InterfaceA>{...}
then the opposite is true; where K::methodB
works and k::MethodA
does not. It appears that the collector can only see the first interface declared for the generic.
I'm not sure if this is an issue with util.Function
or if there is a type issue with the collector.
How can this be fixed so that any number of interfaces are visible to the collector's process?