Skip to content

Commit 6e490df

Browse files
authored
Update how-can-i-initialize-a-static-map.md
修正文中错误代码!
1 parent ca5550b commit 6e490df

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

contents/how-can-i-initialize-a-static-map.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,23 @@
5252

5353
我喜欢用Guava(是 Collection 框架的增强)的方法初始化一个静态的,不可改变的map
5454

55-
static fianl Map<Integer, String> myMap = ImmutablMap.of(
56-
1,"one",
57-
2, "two"
58-
)
55+
static final Map<Integer, String> MY_MAP = ImmutableMap.of(
56+
1, "one",
57+
2, "two"
58+
);
59+
5960
·
6061
当map的 entry个数超过5个时,你就不能使用`ImmutableMap.of`。可以试试`ImmutableMap.bulider()`
6162

62-
static fianl Map<Integer, String> myMap = ImmutableMap.<Integer, String>builder()
63-
{
64-
.put(1, "one")
65-
.put(2, "two")
66-
67-
.put(15, "fifteen")
68-
.build();
69-
}
63+
static final Map<Integer, String> MY_MAP = ImmutableMap.<Integer, String>builder()
64+
.put(1, "one")
65+
.put(2, "two")
66+
// ...
67+
.put(15, "fifteen")
68+
.build();
69+
7070

7171

7272
# 原文链接 #
7373

74-
http://stackoverflow.com/questions/507602/how-can-i-initialize-a-static-map
74+
http://stackoverflow.com/questions/507602/how-can-i-initialize-a-static-map

0 commit comments

Comments
 (0)