How to declare a map with variable generics?

前端 未结 2 695
一整个雨季
一整个雨季 2021-01-12 05:50

I have a Map whose keys are of generic type Key, and values are of type List. If the key is an instance of Key

2条回答
  •  生来不讨喜
    2021-01-12 06:21

    This is what you want:

    public class Test extends HashMap>
    {
    }
    

    If you don't want a HashMap as the super class then change it to whatever concrete class you want.

提交回复
热议问题