Skip to content

1.x: Change the signature of ignoreElements is also an implicit cast to whatever type you want. #3451

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -5592,8 +5592,8 @@ public final <T2, D1, D2, R> Observable<R> groupJoin(Observable<T2> right, Func1
* called by the source Observable
* @see <a href="http://reactivex.io/documentation/operators/ignoreelements.html">ReactiveX operators documentation: IgnoreElements</a>
*/
public final Observable<T> ignoreElements() {
return lift(OperatorIgnoreElements.<T> instance());
public final <R> Observable<R> ignoreElements() {
return lift(OperatorIgnoreElements.<R, T>instance());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, there is no need to add more type parameters but just do an unchecked cast or raw type cast:

@SuppressWarnings("unchecked")
//...
return (Observable)lift(OperatorIgnoreElements.<T>instance());

Note that instance() does this re-cast as well since the operator is stateless.

}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/rx/internal/operators/OperatorIgnoreElements.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
import rx.Observable.Operator;
import rx.Subscriber;

public class OperatorIgnoreElements<T> implements Operator<T, T> {
public class OperatorIgnoreElements<R, T> implements Operator<R, T> {

private static class Holder {
static final OperatorIgnoreElements<?> INSTANCE = new OperatorIgnoreElements<Object>();
static final OperatorIgnoreElements<?, ?> INSTANCE = new OperatorIgnoreElements<Object, Object>();
}

@SuppressWarnings("unchecked")
public static <T> OperatorIgnoreElements<T> instance() {
return (OperatorIgnoreElements<T>) Holder.INSTANCE;
public static <T, R> OperatorIgnoreElements<T, R> instance() {
return (OperatorIgnoreElements<T, R>) Holder.INSTANCE;
}

private OperatorIgnoreElements() {

}

@Override
public Subscriber<? super T> call(final Subscriber<? super T> child) {
public Subscriber<? super T> call(final Subscriber<? super R> child) {
Subscriber<T> parent = new Subscriber<T>() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void call(Integer t) {
}
})
//
.ignoreElements()
.<Integer>ignoreElements()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it prove this breaks the source compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it doesn't prove if it breaks binary compatibility?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to check binary compatibility as part of CI, there are some checker tools that we can include into the build process. Probably, it deserves a separate issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came across a semver for Java library awhile ago that could take two jars and hint if it was major, minor or patch change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized we don't have a guidance on source compatibility explicitly. We only discussed backward compatibility in #1917. But I'm supposed backward compatibility should include both binary and source backward compatibility.

//
.doOnNext(new Action1<Integer>() {

Expand Down