Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
Patch
Description
This is mainly my fault, current Groovy master branch cannot compile this code in @TypeChecked class,
because Iterable.tail() returns Collection.
void test() { assert 2 == foo([1, 2].tail()) } int foo(List<Integer> a) { a[0] }
There is List.tail(), which returns List, but this method is @Deprecated,
and @Deprecated method is not called.
So I created a patch, in which many List methods return List, and also for many other Collection classes.
For example, now List.leftShift() returns List, this code can be compiled in @TypeChecked class.
([1, 2] << 3).each { println it }.collect { it + 1 }.subList(1, 2)
The implementation of List.leftShift() is just this. Only type casts.
public static <T> List<T> leftShift(List<T> self, T value) { return (List<T>) leftShift((Collection<T>) self, value); }
The pull request is here.
https://github.com/groovy/groovy-core/pull/487