- changed title to Type inference error for enhanced-for loop with inferred-type expression
- edited description
Type inference error for enhanced-for loop with inferred-type expression
Issue #285
resolved
ExtendJ 8.1.0-45-g5c1c58b Java SE 7
// Test that enhanced-for can iterate over a generic type created with diamond.
// .result: COMPILE_PASS
import java.util.*;
public class Test {
void test(Collection<String> strs) {
for (String s : new HashSet<>(strs)) {
System.out.println(s);
}
}
}
Expected result: should compile without error.
Actual result: compilation error:
[junit] Compilation failed when expected to pass:
[junit] tests/jsr334/diamond/enhanced_for_01p/Test.java:6: error: parameter of type java.lang.String can not be assigned an element of type java.lang.Object
Additional test without diamond access:
import java.util.*;
public class Test {
void test() {
for (String s : Collections.emptyList()) {
System.out.println(s);
}
}
}
Comments (3)
-
reporter -
reporter - changed status to open
-
reporter - changed status to resolved
- Log in to comment