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

Cannot pass a generic type as an argument #18757

Closed
DartBot opened this issue May 10, 2014 · 2 comments
Closed

Cannot pass a generic type as an argument #18757

DartBot opened this issue May 10, 2014 · 2 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report

Comments

@DartBot
Copy link

DartBot commented May 10, 2014

This issue was originally filed by @jolleekin


Let's say I have a method

    dynamic decode(String text, Type type)

I tried to call it this way

    var x = decode('[1,2,3]', List<int>) as List<int>;

However, the editor says

  • [warning] There is no such operator '<' in 'Type'
  • [error] Expected to find ')'
@lrhn
Copy link
Member

lrhn commented May 10, 2014

The type "List<int>" cannot be expressed directly as a Type literal. In other words "List<int>" is not syntax for a type literal, but is doing "List less than int" and missing an operand for the following "greater than".
You can use "List<int>" as a type expression, so it's ok after "is" or "as" or as a type annotation, but it can't be used where a general expression is expected.

To get the Type of List<int>, you can use a helper class like:
  
  class Typer<T> { Type get type => T; }

  Type listOfInt = new Typer<List<int>>().type;


Added Area-Language, AsDesigned labels.

@gbracha
Copy link
Contributor

gbracha commented Aug 26, 2014

Added Duplicate label.
Marked as being merged into #11923.

@DartBot DartBot added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report labels Aug 26, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

4 participants