as9567585
V2EX  ›  Flutter

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

  •  1
     
  •   as9567585 · May 18, 2022 · 2337 views
    This topic created in 1480 days ago, the information mentioned may be changed or developed.

    3 replies    2022-05-19 00:26:33 +08:00
    dcsuibian
        1
    dcsuibian  
       May 18, 2022 via Android
    没学过 Flutter 。
    你这个 eval 是个能接收 T 类型参数的函数,而不是个能接受 Event 类型的函数。
    比如我来个 AnotherEvent extends Event 。
    这时候 T 就是 AnotherEvent 。
    我 eval 函数能接收 AnotherEvent 关你 SomeEvent 啥事
    hsfzxjy
        3
    hsfzxjy  
       May 19, 2022 via Android
    可以拓展了解两个概念 covariance 和 contravariance
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2874 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 09:05 · PVG 17:05 · LAX 02:05 · JFK 05:05
    ♥ Do have faith in what you're doing.