I'm trying to get my head around a generic-type problem. But it seems like eclipse is complaining while there isn't a valid complaint.
Consider the following methods
public static <FR extends FilterResult, T> List<? super WrappedFilterResult<? super T, FR>> filter(String check, Collection<T> elements, Function<? super T, String> converter, Filter<? extends FR> filter, ACComparator<? super WrappedFilterResult<? super T, ? super FR>> comparator)
{
// eclipse says 'filter' doesn't accept these arguments
return filter(check, elements, new ArrayList<>(), converter, filter, comparator);
// doing a self call will result in the same error?
// return filter(check, elements, converter, filter, comparator);
// calling without returning doesn't solve it either?
// filter(check, elements, converter, filter, comparator);
// return null;
}
// no complaints here
public static <FR extends FilterResult, T, C extends Collection<? super WrappedFilterResult<? super T, FR>>> C filter(String check, Collection<T> elements, C result, Function<? super T, String> converter, Filter<? extends FR> filter, ACComparator<? super WrappedFilterResult<? super T, ? super FR>> comparator)
{
// content
}
For the first method eclipse is complaining it cannot call the filter
method because the method is not applicable for the arguments
. But even if I do a self call it will complain.
Thinking it might be the return type I eliminated it by only calling and returning null
, but sadly that doesn't solve anything either.
Sorry for the complicated method declaration but I have more similar methods with the same kind/amount of parameters working with no problems. So I have no clue why this wouldn't work.
Info:
I hope its something minor I fail to see atm, any help is appreciated.
Thanks in advance
Edit
The class declarations if someone needs them
public static class FilterResult {}
public interface Filter<FR extends FilterResult> {}
public static class WrappedFilterResult<T, FR extends FilterResult> extends FilterResult {}
public interface ACComparator<FR extends FilterResult> {}
Submitted to Bugzilla
I assume it is an Eclipse JDT compiler bug, though I have not consulted the JLS and also don't really feel like digging around in it.
The reasons for my assumption is threefold:
Your code compiles successfully under javac 8u112
I would expect that a method calling itself with its own parameters should compile.
Earlier, I also ran into a case where Eclipse compiler disagreed with other compilers.
public static class FilterResult {}
public static class WrappedFilterResult<T, FR extends FilterResult> extends FilterResult {}
public interface ACComparator<FR extends FilterResult> {}
public static <FR extends FilterResult, T>
void filter1(ACComparator<? super WrappedFilterResult<? super T, ? super FR>> comparator) {
// both compile fine with normal Java compiler
// but error with Eclipse JDT compiler (I'm using Eclipse 4.9.0)
filter1(comparator);
filter2(comparator);
}
public static <FR extends FilterResult, T>
void filter2(ACComparator<? super WrappedFilterResult<? super T, ? super FR>> comparator) {
}
Pulling the offending type (ACComparator<...etc>
in this case) into a generic type argument seems to get past this issue for Eclipse.
public static
< FR extends FilterResult, T,
A extends ACComparator<? super WrappedFilterResult<? super T, ? super FR>> // <-- here
>
void filterSuccess(A comparator) {
// success!
filter1(comparator);
filter2(comparator);
}