Java Generics - How do I call a generic map with a successor object

后端 未结 3 2025
走了就别回头了
走了就别回头了 2021-01-29 11:19

I wrote the following method

 validate(Map map)

And I want to call it with

dogMap = new HashMap

        
3条回答
  •  北恋
    北恋 (楼主)
    2021-01-29 11:57

    You can change the signature of validate to :

    validate(Map map)
    

    This will allow you to pass any map with a String key and a value that extends or implements IAnimal.

提交回复
热议问题