让说我有这样的代码如何在Java中创建一些变量类型别名
Map<String, String> list = new HashMap<String, String>();
list.put("number1", "one");
list.put("number2", "two");
我怎么能做出一些“别名”类型
Map<String, String>
的东西,更容易被改写像
// may be something like this
theNewType = HashMap<String, String>;
theNewType list = new theNewType();
list.put("number1", "one");
list.put("number2", "two");
基本上我的问题是,如何创建一个“类型”的“别名”,所以我可以使它更容易编写和更容易wh需要更改整个程序代码。
谢谢,对不起,如果这是愚蠢的问题。我在Java中有点新鲜。
@Lee - KARASZI伊什特万的关于类型的警告是非常重要的 - 见http://www.ibm.com/developerworks/java/library/j-jtp02216/index.html – McDowell 2011-04-09 11:36:29
谢谢您。我现在使用这个。这有很大帮助。 – Lee 2011-04-10 04:05:23
还有一种替代技巧/黑客可以用泛型来做:http://stackoverflow.com/questions/5604390/how-do-i-create-some-variable-type-alias-in-java/27536347#27536347 – 2014-12-17 22:54:28