Functional Interfaces should be as specialised as possible, but specialized interface does not declare used methods

Rule RSPEC-4276 requires the use of specialized functional interfaces whenever possible, ad example changing Function<Long, T> to LongFunction<T>. However, since LongFunction<T> does not extends Function<Long, T>, default methods compose and andThen are missing, therefore

LongFunction<T> mapper = ...;
mapper.compose(Long::parseLong);

is a compile error.

This is a false positive and should be excluded.

Using java 11, eclipse 2020-09 (4.17.0), SonarLint 5.4.0

Hey @gbaso,

First, let me wish you a nice welcome in our community!

Thanks a lot for your feedback. This is indeed a False-Positive. Once replaced, you won’t be able to call these methods… I created the following ticket to fix this: SONARJAVA-3603

The fix is currently scheduled for our Java analyzer release, expected to be released by the end of the year.

Thanks,
Michael

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.