Flutter主调函数的返回类型隐式限定被调方法返回值的泛型

postJson是被调方法,postRule是主调方法。

1、要被限定的方法

Future<T> postJson<T>(

}

2、显示的限定postJson方法返回值的类型:

static Future<Map<String, dynamic>> postRule() async {

return postJson<Map<String, dynamic>>();

}

扫描二维码关注公众号,回复: 13482758 查看本文章

3、隐式限定

static Future<Map<String, dynamic>> postRule() async {

return postJson();

}

在没有显示限定时,postJson的主调方法postRule的返回值隐式的限定了

postJson方法返回值的类型和postRule的返回值类型一致。

猜你喜欢

转载自blog.csdn.net/gaoyp/article/details/120045634