How do I create some variable type alias in Java

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

    Although Java doesn't support this, you can use a generics trick to simulate it.

    class Test {
         void x(I i, L l) {
            System.out.println(
                i.intValue() + ", " + 
                l.longValue()
            );
        }
    }
    

    Source: http://blog.jooq.org/2014/11/03/10-things-you-didnt-know-about-java/

提交回复
热议问题