How do I create some variable type alias in Java

后端 未结 5 1616
自闭症患者
自闭症患者 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:15

    There are no aliases in Java. You can extend the HashMap class with your class like this:

    public class TheNewType extends HashMap {
        // default constructor
        public TheNewType() {
            super();
        }
        // you need to implement the other constructors if you need
    }
    

    But keep in mind that this will be a class it won't be the same as you type HashMap

提交回复
热议问题