You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class CollectorsToListCheckSequencedSample {
void noncompliant() {
List<String> list = Stream.of("A", "B", "C")
.collect(Collectors.toList()); // Noncompliant {{Replace this usage of 'Stream.collect(Collectors.toList())' with 'Stream.toList()' and ensure that the list is unmodified.}}
// ^^^^^^^^^^^^^^^^^^^
list.getFirst();
}
void compliant() {
List<String> addFirst = Stream.of("B", "C", "D")
.collect(Collectors.toList()); // Compliant, addFirst needs to be mutable
addFirst.addFirst("A");
List<String> addLast = Stream.of("A", "B", "C")
.collect(Collectors.toList()); // Compliant, addLast needs to be mutable