Skip to content

Generics for methods #7099

Closed
Closed
@DartBot

Description

@DartBot

This issue was originally filed by [email protected]


Not able to find much info in the spec for this. Coming from C# I can do things with generics such as...

class A
{
  var _list = new List<B>();

  T add<T>(){
    if(T is B){
      var newT = new T();
      _list.add(newT);
      return newT;
    }
  }
}

abstract class B
{

}

class C extends B
{

}

main(){
  var a = new A();
  var c = a.add<C>();
}

However this doesn't seem supported in Dart; am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).closed-duplicateClosed in favor of an existing reporttype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions