寻找在Java中实现的方法,以定义每个索引具有不同类型的多维数组
像这样......
低于'值'和'活动'是相关的..但缺乏这种结构,它们是独立声明的。
final String[] values = new String[]{
"Config",
"Linking Twitter & Facebook",
"Facebook Direct",
"Twitter Direct",
"Action Bar (Profiled)",
"Sharing",
"Comments",
"Likes",
"Views",
"Entities",
"User Profile (Profiled)",
"Actions (User Activity)",
"Subscriptions",
"Location",
"Init",
"Tools"
};
final Class<?>[] activities = new Class<?>[]{
AuthButtonsActivity.class,
FacebookActivity.class,
TwitterActivity.class,
ActionBarActivity.class,
ShareActivity.class,
CommentActivity.class,
LikeActivity.class,
ViewActivity.class,
EntityActivity.class,
UserActivity.class,
ActionActivity.class,
SubscriptionActivity.class,
LocationActivity.class,
InitActivity.class,
ToolsActivity.class
};
应该声明这样的东西..如果java有支持..
Array<String, Class>[][] valueClasses =
final Array<String, Class>[][] valueClasses = new Array<String, Class>[][]{
{ "Config", AuthButtonsActivity.class },
};
答案 0 :(得分:0)
您可以使用Map
接口的实现。您的初始化代码可以是这样的:
private static Map<String, Class<?>> assembleActivitiesMap() {
Map<String, Class<?>> activities = new HashMap<String, Class<?>>();
activities.put("Config", AuthButtonsActivity.class);
activities.put("Facebook", FacebookActivity.class);
...
return activities;
private final Map<String, Class<?>> activities = assembleActivitiesMap();
答案 1 :(得分:0)
不确定我是按照您要求的方式进行的,但请查看Google Guava中的馆藏。 Multimap
可能就是你要找的东西。