forked from NickyBoy89/java2go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNameCollisions.java
More file actions
50 lines (38 loc) · 1.09 KB
/
Copy pathNameCollisions.java
File metadata and controls
50 lines (38 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.example;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class NameCollisions {
Map<String, Integer> fruitTypes;
// `map` is a reserved keyword
Map<String, Integer> map;
Map<String, Integer> test = new HashMap<>();
// Since `type` is a reserved keyword in Go, this should fail
public int getFruit(String type) {
return this.fruitTypes.get(type);
}
// This is also a collision, with the keyword `range`
private int[] range() {
int[] values = new int[this.map.size()];
int ind = 0;
for (int val : this.map.values()) {
values[ind] = val;
ind++;
}
return values;
}
public NameCollisions() {
// Another collision, but a little more subtle
this.map = new HashMap<>();
}
public static void main(String[] args) {
NameCollisions test = new NameCollisions();
System.out.println(test.map);
// Even more collisions
Map<String, Integer> map = new HashMap<>();
map.put("Apple", 1);
map.put("Lemon", 4);
test.map = map;
System.out.println(Arrays.toString(test.range()));
}
}