Java9CollectionFactoryInspection: add type argument if necessary

This commit is contained in:
Tagir Valeev
2017-02-28 13:05:21 +07:00
parent 03274b0741
commit f36d4710f1
15 changed files with 51 additions and 14 deletions
@@ -5,5 +5,5 @@ import java.util.Collections;
import java.util.List;
public class Test {
public static final List<Number> EVEN = List.of(2, 4, 6, 8, 10);
public static final List<Number> EVEN = List.<Number>of(2, 4, 6, 8, 10);
}
@@ -4,5 +4,5 @@ import java.util.Collections;
import java.util.List;
public class Test {
public static final List<Number> EVEN = List.of(0, 2, 4, 6, 8);
public static final List<Number> EVEN = List.<Number>of(0, 2, 4, 6, 8);
}
@@ -4,7 +4,7 @@ import java.util.*;
public class Test {
public void testList() {
List<Integer> list;
list = List.of(1, 2);
list = List.<Integer>of(1, 2);
System.out.println(list);
}
}
@@ -4,5 +4,5 @@ import java.util.Collections;
import java.util.List;
public class Test {
public static final List<Number> EVEN = List.of(2, 4, 6, 8, 10, 2);
public static final List<Number> EVEN = List.<Number>of(2, 4, 6, 8, 10, 2);
}
@@ -0,0 +1,8 @@
// "Replace with 'List.of' call" "true"
import java.util.*;
public class Test {
public void test() {
List<String[]> list = List.<String[]>of(new String[]{"aaa"});
}
}
@@ -4,6 +4,6 @@ import java.util.*;
public class Test {
public void test() {
Map<String, String> myMap;
myMap = Map.of("a", "1", "b", "1", "c", "1", "d", "1", "e", "1", "f", "1", "g", "1", "h", "1", "i", "1", "j", "1");
myMap = Map.<String, String>of("a", "1", "b", "1", "c", "1", "d", "1", "e", "1", "f", "1", "g", "1", "h", "1", "i", "1", "j", "1");
}
}
@@ -4,6 +4,6 @@ import java.util.*;
public class Test {
public void test() {
Map<String, String> myMap;
myMap = Map.of("a", "b", "c", "b");
myMap = Map.<String, String>of("a", "b", "c", "b");
}
}
@@ -5,5 +5,5 @@ import java.util.HashSet;
import java.util.Set;
public class Test {
public static final Set<String> MY_SET = Set.of("a", "b", "c", Math.random() > 0.5 ? "d" : Math.random() > 0.5 ? "e" : "d");
public static final Set<String> MY_SET = Set.<String>of("a", "b", "c", Math.random() > 0.5 ? "d" : Math.random() > 0.5 ? "e" : "d");
}
@@ -4,5 +4,5 @@ import java.util.HashSet;
import java.util.Set;
public class Test {
public static final Set<String> MY_SET = Set.of("a", "b", "c".toUpperCase());
public static final Set<String> MY_SET = Set.<String>of("a", "b", "c".toUpperCase());
}
@@ -6,6 +6,6 @@ public class Test {
static {
Set<String> set;
MY_SET = Set.of("foo", "bar", "xyz");
MY_SET = Set.<String>of("foo", "bar", "xyz");
}
}
@@ -4,7 +4,7 @@ import java.util.*;
public class Test {
public void test2() {
Set<String> set;
set = Set.of("foo", "bar", "xyz");
set = Set.<String>of("foo", "bar", "xyz");
System.out.println(set);
}
}
@@ -5,5 +5,5 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Test {
public static final List<Class<?>> MY_LIST = List.of(String.class, int.class, Object.class);
public static final List<Class<?>> MY_LIST = List.<Class<?>>of(String.class, int.class, Object.class);
}
@@ -5,5 +5,5 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Test {
public static final Set<Class<?>> MY_SET = Set.of(String.class, int.class, Object.class);
public static final Set<Class<?>> MY_SET = Set.<Class<?>>of(String.class, int.class, Object.class);
}
@@ -0,0 +1,8 @@
// "Replace with 'List.of' call" "true"
import java.util.*;
public class Test {
public void test() {
List<String[]> list = Collections.unmodif<caret>iableList(Arrays.<String[]>asList(new String[] {"aaa"}));
}
}