dart:通用:未使用局部变量“”的值

时间:2018-12-21 21:52:24

标签: dart

您能看到以下泛型有什么问题吗?

您可以在此处查看和修改此代码:https://dartpad.dartlang.org/c417f62f2134a7ab828b36ba70564a8d

// import 'dart:async';

typedef void PrintFunction<T>(String p1, T p2);

class ClassA<String, T> {
  String str;
  T myprinter;

  ClassA({this.str, this.myprinter});
}

class ClassB {
  String str;
}

main() {

var smallClass = ClassB();
var hello = "input string";

PrintFunction<ClassB> mp = (hello, smallClass)=> print('Hello from PrintFunction');

  ClassA s = ClassA(
      str: "",
      myprinter: mp
  );
  s.myprinter();

}

分析器错误,很奇怪:

The value of the local variable 'smallClass' isn't used.
The value of the local variable 'hello' isn't used.

1 个答案:

答案 0 :(得分:1)

这可能有效

    var s = MyClasse<String>(
    t1: "",
    myprinter: p);

您还应该注意,

class MyClasse<T1, MyPrinter>

MyPrinter引入了一个泛型类型变量,它没有引用typedef void MyPrinter