V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
as9567585
V2EX  ›  Flutter

泛型为什么不能用这样用呢

  •  1
     
  •   as9567585 · 2022-05-18 19:39:57 +08:00 · 1581 次点击
    这是一个创建于 700 天前的主题,其中的信息可能已经有所发展或是发生改变。

    3 条回复    2022-05-19 00:26:33 +08:00
    dcsuibian
        1
    dcsuibian  
       2022-05-18 19:52:15 +08:00 via Android
    没学过 Flutter 。
    你这个 eval 是个能接收 T 类型参数的函数,而不是个能接受 Event 类型的函数。
    比如我来个 AnotherEvent extends Event 。
    这时候 T 就是 AnotherEvent 。
    我 eval 函数能接收 AnotherEvent 关你 SomeEvent 啥事
    as9567585
        2
    as9567585  
    OP
       2022-05-18 20:09:18 +08:00
    hsfzxjy
        3
    hsfzxjy  
       2022-05-19 00:26:33 +08:00 via Android
    可以拓展了解两个概念 covariance 和 contravariance
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5551 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 03:35 · PVG 11:35 · LAX 20:35 · JFK 23:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.