Skip to content

Transitive generics? #1692

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
d-markey opened this issue Jun 19, 2021 · 2 comments
Closed

Transitive generics? #1692

d-markey opened this issue Jun 19, 2021 · 2 comments
Labels
feature Proposed language feature that solves one or more problems

Comments

@d-markey
Copy link

Consider the following classes:

  // data with a key
  abstract class Data<K> {
    K get key;
  }
  
  // link to some data
  class Link<K, T extends Data<K>> {
  
    Link({ T? value, K? key }) : _value = value, _key = key;
  
    final K? _key;
    final T? _value;
  }

The Link class has two generics K and T but K could be inferred from T.

Would it be possible to simply write:

  class Link<T extends Data<K>> {
  
    Link({ T? value, K? key }) : _value = value, _key = key;
  
    final K? _key;
    final T? _value;
  }

Currently, client classes look like:

  // some data
  class A implements Data<String> {
    A(this.key);
    final String key;
  }
  
  // some other data
  class B implements Data<int> {
    B(this.key);
    final int key;
    Link<String, A>? property;
  }

The Link<String, A>? property is essentially a Link<A>. String is redundant and is actually forced by the use of A.

@d-markey d-markey added the feature Proposed language feature that solves one or more problems label Jun 19, 2021
@mateusfccp
Copy link
Contributor

Duplicate of #620.

@d-markey
Copy link
Author

Hi, thanks for the feedback. I'll follow up on that one then.

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
Projects
None yet
Development

No branches or pull requests

2 participants