How do I create some variable type alias in Java

后端 未结 5 1625
自闭症患者
自闭症患者 2020-12-03 09:12

let say I have this code

Map list = new HashMap();
list.put(\"number1\", \"one\");
list.put(\"number2\", \"two\")         


        
5条回答
  •  悲&欢浪女
    2020-12-03 10:08

    There is no typedef equivalent in Java, and there is no common idiom for aliasing types. I suppose you could do something like

    class StringMap extends HashMap {}
    

    but this is not common and would not be obvious to a program maintainer.

提交回复
热议问题