Skip to content
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

Varargs cause compiler warnings #359

Closed
samuelgruetter opened this issue Sep 9, 2013 · 9 comments
Closed

Varargs cause compiler warnings #359

samuelgruetter opened this issue Sep 9, 2013 · 9 comments

Comments

@samuelgruetter
Copy link
Contributor

I'm trying to use the concat operator, but I can't use it without getting a compiler warning. Here's my code:

Observable<HorrorMovie> horrorMoviesWithException() {
    Observable<HorrorMovie> movies = Observable.from(new HorrorMovie());
    Observable<HorrorMovie> ex = Observable.error(new Exception("test")); 
    return Observable.concat(movies, ex); // (WARNING)
}

I get the warning "Type safety: A generic array of Observable<CovarianceTest.HorrorMovie> is created for a varargs parameter".

This problem was discussed on stackoverflow and this bug report explains why it's not going to be fixed.

@samuelgruetter
Copy link
Contributor Author

The same problem also occurs with merge, mergeDelayError, and if arguments with generic type are passed to from and startWith, they are also affected.

@samuelgruetter
Copy link
Contributor Author

Unless someone shows me how to get rid of this warning without using @SuppressWarnings("unchecked"), I would suggest that we remove the varargs methods and add instead

  • an overloaded method for each arity
  • a method taking an Iterable (will be used by the Scala adaptor)

@abersnaze
Copy link
Contributor

Like the zip operator?

Sent from my iPhone

On Sep 9, 2013, at 1:50 AM, samuelgruetter [email protected] wrote:

Unless someone shows me how to get rid of this warning without using @SuppressWarnings("unchecked"), I would suggest that we remove the varargs methods and add instead

an overloaded method for each arity
a method taking an Iterable (will be used by the Scala adaptor)

Reply to this email directly or view it on GitHub.

@samuelgruetter
Copy link
Contributor Author

yes

@benjchristensen
Copy link
Member

That issue with varargs is definitely one of the weaknesses of generics.

How about if we had overloads for up to 9 arities, and then on that one have a 10th vararg for scenarios were people truly do want/need more? That way it would only affect someone using beyond 9 args?

@samuelgruetter
Copy link
Contributor Author

I don't quite get what you mean by "a 10th vararg for scenarios..." but I'd also be fine with overloads for up to 9 arguments, plus another overload which takes only 1 argument of type Collection<Observable<T>> or Iterable<Observable<T>>, so if people want more than 9 arguments, they have to construct a list containing the arguments and pass this list to concat.

@benjchristensen
Copy link
Member

I meant something like this ...

concat(T t1, T t2)
... etc ...
concat(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8)
concat(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8, T t9)
concat(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8, T t9, T... rest)

I will start refactoring vararg method signature later today or tonight (US Pacific time) unless someone else is already doing it. If one of you already are tackling this please let me know here so we don't replicate effort.

@benjchristensen
Copy link
Member

Closing as I have removed all varargs from Observable.

samuelgruetter pushed a commit that referenced this issue Nov 17, 2013
rickbw pushed a commit to rickbw/RxJava that referenced this issue Jan 9, 2014
rickbw pushed a commit to rickbw/RxJava that referenced this issue Jan 9, 2014
ReactiveX#359 Varargs cause compiler warnings

As part of this I also changed this:

```java
public static <T> Observable<T> concat(Observable<Observable<? extends T>> observables)
```

to

```java
public static <T> Observable<T> concat(Observable<Observable<T>> observables)
```

I documented the reasoning of this at ReactiveX#360 (comment)
rickbw pushed a commit to rickbw/RxJava that referenced this issue Jan 9, 2014
rickbw pushed a commit to rickbw/RxJava that referenced this issue Jan 9, 2014
rickbw pushed a commit to rickbw/RxJava that referenced this issue Jan 9, 2014
rickbw pushed a commit to rickbw/RxJava that referenced this issue Jan 9, 2014
billyy pushed a commit to billyy/RxJava that referenced this issue Jan 13, 2014
ReactiveX#359 Varargs cause compiler warnings

As part of this I also changed this:

```java
public static <T> Observable<T> concat(Observable<Observable<? extends T>> observables)
```

to

```java
public static <T> Observable<T> concat(Observable<Observable<T>> observables)
```

I documented the reasoning of this at ReactiveX#360 (comment)
billyy pushed a commit to billyy/RxJava that referenced this issue Jan 13, 2014
billyy pushed a commit to billyy/RxJava that referenced this issue Jan 13, 2014
billyy pushed a commit to billyy/RxJava that referenced this issue Jan 13, 2014
billyy pushed a commit to billyy/RxJava that referenced this issue Jan 13, 2014
@benjchristensen
Copy link
Member

The @SafeVarargs annotation allows us to solve this. Trying to figure out if we can leverage this Java 7 feature without breaking Android support (which is obviously more important).

zsxwing pushed a commit to zsxwing/RxScala that referenced this issue Aug 19, 2014
zsxwing pushed a commit to zsxwing/RxScala that referenced this issue Aug 19, 2014
benjchristensen added a commit to ReactiveX/RxScala that referenced this issue Aug 19, 2014
benjchristensen added a commit to ReactiveX/RxScala that referenced this issue Aug 19, 2014
benjchristensen added a commit to ReactiveX/RxScala that referenced this issue Aug 19, 2014
benjchristensen added a commit to ReactiveX/RxScala that referenced this issue Aug 19, 2014
benjchristensen added a commit to ReactiveX/RxScala that referenced this issue Aug 19, 2014
benjchristensen added a commit to ReactiveX/RxScala that referenced this issue Aug 19, 2014
benjchristensen added a commit to ReactiveX/RxScala that referenced this issue Aug 19, 2014
benjchristensen added a commit to ReactiveX/RxScala that referenced this issue Aug 19, 2014
jihoonson pushed a commit to jihoonson/RxJava that referenced this issue Mar 6, 2020
…. Added support for Maybe.

* Upgrade RxJava2 version to 2.2.7

Recently RxJava folks inlined the SubscriptionHelper.isCancelled,
so the method had to be inlined in our code as well.

* Retry transformer for RxJava2 Completable type

This type returns no values at all. It finishes either with onComplete
or onError, so in order to properly count the successful calls without
retry attempt we need to count onComplete as success.

* RxJava2 support for retryOnResult

* Stop using RxJava internal API in RetryTransformer + support for Maybe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants