-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exploit generic variance to ensure typing works as best as possible #1533
Labels
Milestone
Comments
@0crat in |
victornoel
added a commit
to victornoel/cactoos
that referenced
this issue
Jan 16, 2021
baudoliver7
pushed a commit
to baudoliver7/cactoos
that referenced
this issue
Mar 8, 2021
baudoliver7
pushed a commit
to baudoliver7/cactoos
that referenced
this issue
Mar 8, 2021
baudoliver7
pushed a commit
to baudoliver7/cactoos
that referenced
this issue
Mar 9, 2021
baudoliver7
pushed a commit
to baudoliver7/cactoos
that referenced
this issue
Mar 13, 2021
baudoliver7
pushed a commit
to baudoliver7/cactoos
that referenced
this issue
Mar 13, 2021
baudoliver7
pushed a commit
to baudoliver7/cactoos
that referenced
this issue
Mar 13, 2021
This was referenced Mar 14, 2021
@baudoliver7 thx |
@sereshqua/z please review this job completed by @baudoliver7/z, as in §30; the job will be fully closed and all payments will be made when the quality review is completed |
@0crat quality good |
DmitryBarskov
added a commit
to DmitryBarskov/cactoos
that referenced
this issue
Apr 1, 2022
DmitryBarskov
added a commit
to DmitryBarskov/cactoos
that referenced
this issue
Apr 1, 2022
@victornoel 4 puzzles #unknown, #unknown, #unknown, #unknown are still not solved. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lots of constructors and methods in cactoos take
Iterable
,Scalar
,Func
and so on.Because of the way typing works in Java, it can sometimes be challenging to have code compile even though it is conceptually sound. For example if we have a method or a constructor like this:
Then the following happens;
In more complex situation, type inference does not even succeed.
The typical solution is to ensure that when using generics as parameters, then variance should be properly defined. The basic rules is that if a generic type is used in outputs of the interface methods, it should be relaxed w.r.t to its subclasses and if it is an input, then w.r.t. its parent classes. For, the above example, this gives us:
Of course this only makes sense if the type parameter is either a non-final class or a generic type from the enclosing class or method.
So every where Iterable, Iterator, Scalar, Callable, Supplier, Func, Proc, BiFunc, BiProc are used we need:
Let's start by package bytes and go on through all of them one by one in alphabetical order by introducing todos once a package or part of it is done. Let's also add some more tests when it makes sense to validate it compiles correctly.
The text was updated successfully, but these errors were encountered: