10
|
1 |
/*
|
|
2 |
* @test /nodynamiccopyright/
|
|
3 |
* @bug 6227617
|
|
4 |
* @summary Lint option for redundant casts
|
|
5 |
* @compile -Werror T6227617.java
|
|
6 |
* @compile/ref=T6227617.out -XDstdout -XDrawDiagnostics -Xlint:cast T6227617.java
|
|
7 |
*/
|
|
8 |
import java.util.HashMap;
|
|
9 |
import java.util.Map;
|
|
10 |
|
|
11 |
class T6227617 {
|
|
12 |
void m() {
|
|
13 |
int i1 = 2;
|
|
14 |
int i2 = (int) i1; // warn
|
|
15 |
|
|
16 |
float f1 = 1f;
|
|
17 |
int i3 = (int) f1;
|
|
18 |
|
|
19 |
String s = (String) ""; // warn
|
|
20 |
Object o = (Object) "";
|
|
21 |
|
|
22 |
Map<String, Integer> m = new HashMap<String, Integer>();
|
|
23 |
Integer I1 = (Integer) m.get(""); // warn
|
|
24 |
}
|
|
25 |
|
|
26 |
// The following cause NPE in Attr with an Attr-based solution for -Xlint:cast
|
|
27 |
static final int i1 = Foo.i1;
|
|
28 |
static final String s = Foo.s;
|
|
29 |
}
|
|
30 |
|
|
31 |
class Foo
|
|
32 |
{
|
|
33 |
static final int i1 = (int) 1;
|
|
34 |
static final int i2 = (int) 1L;
|
|
35 |
|
|
36 |
static final String s = (String) "abc";
|
|
37 |
}
|