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

Allowing a type parameter to extend more than one type. #3960

Closed
FabrizioG202 opened this issue Jul 4, 2024 · 1 comment
Closed

Allowing a type parameter to extend more than one type. #3960

FabrizioG202 opened this issue Jul 4, 2024 · 1 comment
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists

Comments

@FabrizioG202
Copy link

I have the following classes while building a package to abstract reading of different sources:

  • ReadMixin on DataSource, which provides a read() method.
  • SeekMixin on DataSource, which provides a seek(position) method.

Some DataSources, for example one wrapping a file implement both.

Is there currently a way to define a function which accepts a DataSource which implements Both mixins? I would expect somethhing like this to work:

T myFunction<T extends ReadMixin with SeekMixin>(T param) {}

but it does not.

I have found similar issues asking for a similar concepts but for unrelated types, like #2161 (String and Iterable<String>), but I have not found an issue talking about 'related' types, like what I am trying to achieve.

Is there currently a way to do this?

@FabrizioG202 FabrizioG202 added the feature Proposed language feature that solves one or more problems label Jul 4, 2024
@lrhn
Copy link
Member

lrhn commented Jul 4, 2024

There is no way to do that in the current langauge. Each mixin introduces a new type, and those types are unrelated.
They happen to have a shared supertype, but all types do (if nothing else then Object?).

There are other requests for multiple upper bounds, fx #2709 and #1152.
I'll defer to those issues.

@lrhn lrhn closed this as completed Jul 4, 2024
@lrhn lrhn added the state-duplicate This issue or pull request already exists label Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants