inference variables: ensure variable is not mixed with type parameter for recursive calls (IDEA-147639)

This commit is contained in:
Anna Kozlova
2015-11-09 19:08:30 +01:00
parent 289aea179d
commit c798f3ab6b
3 changed files with 51 additions and 1 deletions
@@ -0,0 +1,35 @@
import java.util.*;
import java.util.stream.Collectors;
class Test {
private <S> List<S> bar(List<S> list) {
return null;
}
private <E> List<List<E>> foo(List<E> l) {
foo(bar(l));
final List<List<Object>> perms = foo(null);
return null;
}
public static <E> List<E> pipe(E head, List<E> tail) {
List<E> newList = new ArrayList<>(tail);
newList.add(0, head);
return newList;
}
public static <E> List<E> subtract(List<E> list, E e) {
List<E> newList = new ArrayList<>(list);
newList.remove(e);
return newList;
}
public static <E> List<List<E>> perms(List<E> l) {
return l.isEmpty()
? Collections.singletonList(Collections.emptyList())
: l.stream().flatMap(h -> perms(subtract(l, h)).stream()
.map(t -> pipe(h, t))).collect(Collectors.toList());
}
public static void main(String[] args) {
System.out.println(perms(Arrays.asList("a", "b", "c")));
}
}