How do I resolve ambiguous methods caused by intersection types in Java generics?

前端 未结 5 399
猫巷女王i
猫巷女王i 2020-12-31 16:52

I just recently discovered that you can specify multiple types in a single type parameter bound (see example). Like any new tool, I\'ve been trying to explore the possibilit

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 17:30

    Note that you do not have a real problem, as the methods you are interested in calling are already called due to dynamic binding.

    Running dispatch((Soup) new AlphabetSoup()); yields:

    Reciting ABCs...
    a
    b
    c
    Eating some soup...
    Mmm Mmm Good!
    

    Hence, the AlphabetSoup method are already called due to basic polymorphic behavior.

提交回复
热议问题