主要问题是,需要保存非常大量的字符串常量。
我希望可以把这些常量管理起来。所以现在是使用大量的内部类管理。
不仅包含大量的内部类。内部类中还包含内部类。不知道这样会不会影响性能问题。
示例:
```
public final class WmsUrlConstants {
public static final String URL_WMS_DEFAULT_INDEX = "/wms/default/index";
public static final class Transfer {
public static final String search = "/wms/transfer/list/search";
public static final String delete = "/wms/transfer/list/delete";
public static final String get = "/wms/transfer/edit/getTransfer";
public static final String submit = "/wms/transfer/edit/submitTransfer";
public static final String save = "/wms/transfer/edit/saveTransfer";
public static final String create = "/wms/transfer/edit/create";
public static final class Package {
public static final String save = "/wms/transfer/edit/savePackage";
public static final String delete = "/wms/transfer/edit/deletePackage";
public static final class Item {
public static final String select = "/wms/transfer/edit/getPackageItems";
}
}
public static final class Product {
public static final class Sku {
public static final String get = "/wms/transfer/edit/getSkuByCode";
}
}
public static final class Store {
public static final String all = "/wms/transfer/edit/getAllWarehouses";
}
}
}
1
Septembers 2015-05-02 16:04:06 +08:00
HashMap更合适如果觉得性能差可以考虑用Trie(Prefix Tree)实现Key的匹配
|
2
Septembers 2015-05-02 16:07:43 +08:00
内部类 JDK会拍平
字节码大概会变成 Transfer$Product$Sku 这样 |
3
9hills 2015-05-02 17:03:09 +08:00 via iPhone
Python 的话一个字典就好了
|
4
SoloCompany 2015-05-02 17:39:23 +08:00 via Android
字符串常量会被直接内联,多余的担心
|
5
SoloCompany 2015-05-02 17:40:48 +08:00 via Android
java 没有 define,这种字符串常量的定义方法就是官方指定的和define类似的替代
|
6
smithtel 2015-05-06 09:08:31 +08:00
这些是直接放入常量池中,不会有性能问题,相反放入其他比如list中,还需要对其维护。
|