1 | package testcode;
|
---|
2 |
|
---|
3 | import java.util.Collections;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.Map;
|
---|
6 | import java.util.Set;
|
---|
7 |
|
---|
8 | import org.eclipse.jdt.annotation.NonNull;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * Tests of casting. These are tricky as java has quite some machinery, like
|
---|
12 | * widening narrowing truncating etc.
|
---|
13 | */
|
---|
14 | public class Casts {
|
---|
15 |
|
---|
16 | static public void main(String[] args) {
|
---|
17 | final float x = 3.2f;
|
---|
18 | System.out.println((int) (x + 1));
|
---|
19 | System.out.println((double) 1);
|
---|
20 | System.out.println((char) 65);
|
---|
21 | System.out.println((int) '0');
|
---|
22 | System.out.println((byte) 12);
|
---|
23 | System.out.println((byte) -12);
|
---|
24 | System.out.println((byte) 128);
|
---|
25 | System.out.println((byte) -128);
|
---|
26 | System.out.println((byte) -129);
|
---|
27 |
|
---|
28 | // the implementation is still partial and
|
---|
29 | // therefore the tests are too.
|
---|
30 |
|
---|
31 | int val = 3;
|
---|
32 | char letter = 'C';
|
---|
33 | byte b = 80;
|
---|
34 | System.out.println(String.valueOf(val));
|
---|
35 | System.out.println(String.valueOf(letter));
|
---|
36 | System.out.println(((Byte) b).toString());
|
---|
37 | System.out.println(String.valueOf(b));
|
---|
38 |
|
---|
39 | float[][] values = new float[3][3];
|
---|
40 | values[1][1] = 0;
|
---|
41 | Float f = (values[1][1]);
|
---|
42 | System.out.println(f.toString());
|
---|
43 | testDictKeys();
|
---|
44 | }
|
---|
45 |
|
---|
46 | static void testDictKeys() {
|
---|
47 | final @NonNull Map<@NonNull String, @NonNull String> map = new HashMap<>();
|
---|
48 | map.put("a", "1");
|
---|
49 | map.put("b", "2");
|
---|
50 |
|
---|
51 | final @NonNull Set<@NonNull String> keys = map.keySet();
|
---|
52 | System.out.println(keys.size());
|
---|
53 | System.out.println(Collections.unmodifiableSet(keys).size());
|
---|
54 |
|
---|
55 | keys.remove("a");
|
---|
56 | System.out.println(map.size());
|
---|
57 |
|
---|
58 | }
|
---|
59 |
|
---|
60 | }
|
---|