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

Incorrect generic types for Ordered slot #799

Open
bmorris591 opened this issue May 24, 2016 · 4 comments
Open

Incorrect generic types for Ordered slot #799

bmorris591 opened this issue May 24, 2016 · 4 comments

Comments

@bmorris591
Copy link
Contributor

OrderedSlot should probably have the following signature:

static class OrderedSlot<T extends PresenterWidget<?> & Comparable<? extends T>> {
}

This is because it is currently impossible to have a common generic baseclass for widgets that need to be members of an OrderedSlot.

Consider the following example (sorry, it's quite horrible):

interface View {}

abstract class PresenterWidget<V extends View> {}

class OrderedSlot<T extends PresenterWidget<?> & Comparable<T>> {}

interface UiHandlers {}

interface ViewWithUiHandlers<UIH extends UiHandlers> extends View {}

abstract class BasePresenter<UIH extends UiHandlers, V extends ViewWithUiHandlers<UIH>> extends PresenterWidget<V> implements Comparable<BasePresenter<UIH, V>> {}

So the View, PresenterWidget, OrderedSlot, UIHandlers, ViewWithUiHandlers emulate existing GWTP classes.

I have added a custom base presenter class BasePresenter which is generic in the UIHandlers and the ViewWithUiHandlers. It also is Comparable to itself.

Now, in order for another Presenter to have a Slot that accepts presenters extending this base class, I would need to following OrderedSlot declaration:

final OrderedSlot<BasePresenter<?, ?>> slot = new OrderedSlot<>();

But this will result in a compiler error:

/home/boris/.../App.java
    Error:Error:line (6)java: type argument com.example.testbench.App.BasePresenter<?,?> is not within bounds of type-variable T
    Error:Error:line (6)java: incompatible types: cannot infer type arguments for com.example.testbench.App.OrderedSlot<>
    reason: inferred type does not conform to equality constraint(s)
      inferred: com.example.testbench.App.BasePresenter<capture#1 of ?,capture#2 of ?>
      equality constraints(s): com.example.testbench.App.BasePresenter<capture#1 of ?,capture#2 of ?>,com.example.testbench.App.BasePresenter<?,?>

This is because the compiler cannot find type bounds on the wildcards ?, ? such that the self type & Comparable<T> is satisfied. And this makes sense, as if I create two extension classes and add them both to the OrderedSlot<BasePresenter<?, ?>>

class PresenterOne extends BasePresenter<SomeUiHandlers, ViewWithUiHandlers<SomeUiHandlers>> {}

class PresenterTwo extends BasePresenter<OtherUiHandlers, ViewWithUiHandlers<OtherUiHandlers>> {}

Then as PresenterOne implements Comparable<BasePresenter<SomeUiHandlers, ViewWithUiHandlers<SomeUiHandlers>> and PresenterTwo implements Comparable<BasePresenter<OtherUiHandlers, ViewWithUiHandlers<OtherUiHandlers>> the type equality constraint is violated.

In order for this situation to work, the type constraint on OrderedSlot needs to be relaxed.

@olafleur
Copy link
Member

Would you like to submit a pull request to fix that issue?

@abaranguan
Copy link

I'm facing this issue right now.

👍 to this feature

@bmorris591
Copy link
Contributor Author

@olafleur sorry; haven't had much time recently - I'll try and push something before next week.

@olafleur
Copy link
Member

No worries. If you need help in the process, just ping us here!

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