diamonds; actual types accepted in java 7 even if no formal types were defined!

(cherry picked from commit 903984b162008a56def605c72743c22517304a2d)
This commit is contained in:
anna
2011-05-02 21:14:20 +02:00
parent 430f611e7d
commit 3bb0c9d03a
8 changed files with 124 additions and 18 deletions
@@ -108,4 +108,26 @@ class FI1 {
return null;
}
};
}
}
class Super<X,Y> {
private Super(Integer i, Y y, X x) {}
public Super(Number n, X x, Y y) {}
}
class TestMySuper {
Super<String,Integer> ssi1 = new Super<>(1, "", 2);
}
class TestLocal<X> {
class Member { }
static class Nested {}
void test() {
class Local {}
Member m = new Member<<error descr="Diamond operator is not applicable for non-parameterized types"></error>>();
Nested n = new Nested<<error descr="Diamond operator is not applicable for non-parameterized types"></error>>();
Local l = new Local<<error descr="Diamond operator is not applicable for non-parameterized types"></error>>();
}
}
@@ -0,0 +1,10 @@
class Neg12 {
static class Foo<X> {
<T> Foo(T t) {}
}
Foo<Integer> fi1 = new <<error descr="Actual type argument and inferred type contradict each other">String</error>> Foo<>(1);
Foo<Integer> fi2 = new <<error descr="Actual type argument and inferred type contradict each other">String</error>> Foo<Integer>(1);
Foo<Integer> fi3 = new Foo<Integer>(1);
}
@@ -0,0 +1,9 @@
class Neg13 {
static class Foo<X> {
<T> Foo(T t) {}
}
Foo<Integer> fi1 = new <error descr="Wrong number of type arguments: 2; required: 1"><String, Integer></error> Foo<>("");
Foo<Integer> fi2 = new <error descr="Wrong number of type arguments: 2; required: 1"><String, Integer></error> Foo<Integer>("");
}
@@ -0,0 +1,9 @@
class Neg14 {
static class Foo<X> {
<T extends Integer> Foo(T t) {}
}
Foo<Integer> fi1 = new <<error descr="Actual type argument and inferred type contradict each other">String</error>> Foo<>(1);
Foo<Integer> fi2 = new <<error descr="Actual type argument and inferred type contradict each other">String</error>> Foo<Integer>(1);
}
@@ -0,0 +1,13 @@
class Pos8 {
static class Foo<X> {
Foo(X t) {}
}
Foo<Integer> fi1 = new Foo<>(1);
Foo<Integer> fi2 = new Foo<Integer>(1);
Foo<Integer> fi3 = new <String> Foo<>(1);
Foo<Integer> fi4 = new <String> Foo<Integer>(1);
Foo<Integer> fi5 = new <String, String> Foo<>(1);
Foo<Integer> fi6 = new <String, String> Foo<Integer>(1);
}
@@ -0,0 +1,10 @@
class Pos9<X> {
Pos9(X x) {}
Pos9<X> test(X x) {
return new Pos9<>(x);
}
}