google / google/error-prone

Check that a method signature conforms to a functional interface

Open
#516 5 comments 2 reactions 0 assignees View on GitHub
Type-NewCheck
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

It would be useful to have an annotation like `@ConformsTo(Callable.class)` one can use on a method, which error-prone can check at compile time. Making sure that methods intended for use with Streams API as combiners or merge operators have the correct signature one possible use case; verifying signatures for methods intended for reflective use is another (admittedly minor) case.

It's probably best to have a way to indicate our intention about the receiver: `@ConformsTo(statically = AsyncFunction.class)` would be equivalent to `@ConformsTo(AsyncCallable.class)` on an (instance) method with with the signature `ListenableFuture doWork()`.

The annotations above are really straw-man examples; if you think this is worthwhile we can think about better alternatives.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.