ADDITIONAL SYSTEM INFORMATION :
javac -version
javac 22
A DESCRIPTION OF THE PROBLEM :
The following program compiles, although there's a type error on line 11 when calling the <T> spliterator using a type argument of type String. The spliterator method expects something of type Iterator<? super String>, but the argument of this method has type PrimitiveIterator.OfInt.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.util.*;
public class Test {
public static void main(String[] args) {
List<Integer> lst = new LinkedList<>();
lst.add(2);
lst.add(1);
lst.add(3);
PrimitiveIterator.OfInt iterator = lst.stream().mapToInt(Integer::intValue).iterator();
Spliterator.OfInt x = java.util.Spliterators.<String>spliterator(java.util.Spliterators.iterator(java.util.Spliterators.spliterator(iterator, 0, 2)), 0, 1);
System.out.println(x.characteristics());
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should have been rejected with an error message of the form:
Spliterator<String> was expected; but Spliterator.OfInt was found.
ACTUAL -
The compiler accepts the code.
javac -version
javac 22
A DESCRIPTION OF THE PROBLEM :
The following program compiles, although there's a type error on line 11 when calling the <T> spliterator using a type argument of type String. The spliterator method expects something of type Iterator<? super String>, but the argument of this method has type PrimitiveIterator.OfInt.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.util.*;
public class Test {
public static void main(String[] args) {
List<Integer> lst = new LinkedList<>();
lst.add(2);
lst.add(1);
lst.add(3);
PrimitiveIterator.OfInt iterator = lst.stream().mapToInt(Integer::intValue).iterator();
Spliterator.OfInt x = java.util.Spliterators.<String>spliterator(java.util.Spliterators.iterator(java.util.Spliterators.spliterator(iterator, 0, 2)), 0, 1);
System.out.println(x.characteristics());
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should have been rejected with an error message of the form:
Spliterator<String> was expected; but Spliterator.OfInt was found.
ACTUAL -
The compiler accepts the code.