File: Marks7.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,840 kB
  • sloc: java: 145,910; xml: 839; sh: 518; makefile: 401; perl: 26
file content (19 lines) | stat: -rw-r--r-- 602 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

/**
 * Test cases for Rule #7: "Don't use an Optional to wrap any collection type (List, Set, Map).
 * Instead, use an empty collection to represent the absence of values.
 */
public class Marks7 {

    void illegalInstantiations() {
        // :: error: (optional.collection)
        Optional<List<String>> ols = Optional.of(new ArrayList<String>());
        // :: error: (optional.collection)
        Optional<Set<String>> oss = Optional.of(new HashSet<String>());
    }
}