FuncN generic varargs parameter
See original GitHub issueAs mentioned [1] [2] it would be nice for Observable.zip(iterable, funcn)
to handle iterables of the same type, without having to go about casting the object to an integer for making something like this to work
List<Observable<Integer>> iterable = Arrays.asList(Observable.from(1), Observable.from(2), Observable.from(3));
Observable<List<Integer>> observable = Observable.zip(iterable, Arrays::asList);
Making FuncN<R>
into FuncN<T, R>
kind of snowballed on me as I reached the OperatorZip$Zip
which seems to be needing the Object
type.
Issue Analytics
- State:
- Created 9 years ago
- Comments:15 (10 by maintainers)
Top Results From Across the Web
Java generics and varargs - Stack Overflow
The intention here is to assert that all parameters passed to this function are Class objects extending the Class given as the first...
Read more >Item 32: Combine generics and varargs judiciously - InformIT
Recall that a generic array is created when the method is invoked, to hold the varargs parameters. If the method doesn't store anything...
Read more >Effective Java! Combine Generics and Varargs Judiciously
If we create a function that takes a non-reifiable varargs parameter we are presented with a warning talking about Possible heap pollution ....
Read more >Fixing ugly Java APIs: read-only generic varargs
"unchecked generics array creation for varargs parameter" ... declared as covariant automatically, which makes them read-only inside the varargs function.
Read more >Java Varargs with examples - CodeGym
In case you forgot, this is a variable-length argument. ... Unchecked generics array creation for varargs parameter. What does that mean?
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is how we solved the problem in Kotlin:
I came across this same issue, but with
combineLatest
. I see how it causes an incompatibility, but I’d like this to be reconsidered for v2.Currently I’m using the following overload of
combineLatest
:The definition of
FuncN
is:Firstly, the type information gets lost. A user would presume
T
is passed, but it is actuallyObject
. This caused quite a bit of confusion when using RxJava in Kotlin, where all types can be implicitly resolved and the end of an chain would result in some form ofObject
. Going back up the chain to see what function had misbehaving type information resulted incombineLatest
.Additionally, I personally find the use of varargs a bit confusing. I passed in a
List
and I assume aList
is passed to thecombineFunction
. Instead it is an Array/[]
, but it is not explicitly typed as an array (as it is typed using varargs). I see how varargs would fitcombineFunction
ifcombineLatest
was called with varargs, but in this particular overload it is not.It might be a good idea to introduce the following function definition for V2:
That way a list is passed into
combineLatest
and a list is passed to thecombineFunction
. That way, no type information is lost.