Skip to content

Empty, Error and Never overloads with type witness #654

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

Closed
wants to merge 1 commit into from

Conversation

akarnokd
Copy link
Member

Witness variants for #653.

@akarnokd akarnokd mentioned this pull request Dec 22, 2013
25 tasks
@cloudbees-pull-request-builder

RxJava-pull-requests #587 SUCCESS
This pull request looks good

@zsxwing
Copy link
Member

zsxwing commented Dec 23, 2013

Is it necessary to have such overloads? I just think it's weird that passing an unused var.

@samuelgruetter
Copy link
Contributor

I think this witness trick is common in C#, but I've never seen it in Java, so I would not add these overloads.

@akarnokd
Copy link
Member Author

It depends on how many times you write the following pattern:

import static rx.Observable.*;

concat(from(1,2,3), empty()); // incompatible types Object vs Integer in Java < 8
concat(from(1,2,3), empty(4));
concat(from(1,2,3), Observable.<Integer>empty());

merge(just(4), error(new Exception()); // incompatible types Object vs Integer in Java < 8
merge(just(4), error(new Exception(), 5);
merge(just(4), Observable.<Integer>error(new Exception());

@benjchristensen
Copy link
Member

Instead of adding overloads everywhere we have the cast operator that solves this issue so a user can do either of these:

Observable<String> s = Observable.empty().cast(String.class).take(1)
Observable<String> s = Observable.<String>empty().take(1);

Even if we were to use the witness patter it would be better to take Class<T> rather than T so that we don't have to pass random values in.

Observable<String> s = Observable.empty(String.class).take(1);

This is equally elegant but requires overloads for all similar use cases.

In .Net this is essential because you cannot write the type of an anonymous type (as per @headinthebox ) and this isn't a problem in Java.

@akarnokd akarnokd deleted the WitnessVariants branch January 13, 2014 09:57
jihoonson pushed a commit to jihoonson/RxJava that referenced this pull request Mar 6, 2020
This commit adds support for adding tags to Retry, CircuitBreaker,
Ratelimiter and Bulkhead functionality.

These tags can then be used by other modules for example Prometheus,
MicroMeter, etc.
jihoonson pushed a commit to jihoonson/RxJava that referenced this pull request Mar 6, 2020
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

Successfully merging this pull request may close these issues.

5 participants