Open GoogleCodeExporter opened 8 years ago
This is not a bug.
If you look on following definition from Groovy you will find that typeof(new
HashSet() + 1) == Collection<Integer>
public static <T> Collection<T> plus(Collection<T> left, T right) {
//...
}
so method
public static <T> Set<T> unmodifiableSet(Set<? extends T> s) {
is not applicable.
Original comment by alex.tka...@gmail.com
on 22 Mar 2011 at 6:16
If you don't want to call it a bug, call it a request for feature.
However as long a the code for plus uses cloneSimilarCollection, the compiler
can assert that the return type of plus is the same as the first parameter, and
it is worth adding a type cast after the method call.
Appendix:
public static <T> Collection<T> plus(Collection<T> left, Collection<T> right) {
final Collection<T> answer = cloneSimilarCollection(left, left.size() + right.size());
answer.addAll(right);
return answer;
}
Original comment by manu....@gmail.com
on 23 Mar 2011 at 9:33
Original issue reported on code.google.com by
manu....@gmail.com
on 22 Mar 2011 at 12:07