Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.8
-
None
Description
I thought I had reported this earlier, but I couldn't find the duplicate.
When using a very basic method reference, the STC is inferring Closure as the type instead of the proper functional interface. Explicitly specify as works, which I think might not have with the :: syntax previously.
In my particular case, I'm wrapping a List<DeleteItemRequest> (from the Amazon SDK 2 DynamoDB client) into a Map<String, List<DeleteItemRequest>> to feed to its batch API. The line is:
def requestItems = batch.stream().collect(toMap(DeleteItemRequest::tableName, List::of))
In contrast to GROOVY-9881, it seems the STC is correctly identifying the signature, at least, but it's inferring Closure where Function is expected:
/home/christopher/path/CleanupHandler.groovy: 50: [Static type checking] - Cannot call <T,K,U> java.util.stream.Collectors#toMap(java.util.function.Function <? super T, ? extends K>, java.util.function.Function <? super T, ? extends U>) with arguments [groovy.lang.Closure <java.lang.String>, groovy.lang.Closure <java.util.List>]
Adding an explicit as Function to each reference fixes the problem (though it is still using getMethodPointer instead of real method references).
Attachments
Issue Links
- is duplicated by
-
GROOVY-10613 Fail to infer correct types for fluent method calls
-
- Closed
-