StreamApiMigrationInspection: use toList()/toSet() collector if target variable type is Collection

This commit is contained in:
Tagir Valeev
2016-09-06 11:56:13 +07:00
parent 3a3c613446
commit f0276b724d
3 changed files with 34 additions and 2 deletions
@@ -0,0 +1,15 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Collect {
class Person {
String getName() {
return "";
}
}
void collectNames(List<Person> persons){
Collection<String> names = persons.stream().map(Person::getName).collect(Collectors.toList());
}
}
@@ -0,0 +1,17 @@
// "Replace with collect" "true"
import java.util.*;
public class Collect {
class Person {
String getName() {
return "";
}
}
void collectNames(List<Person> persons){
Collection<String> names = new ArrayList<>();
for (Person person : pers<caret>ons) {
names.add(person.getName());
}
}
}