SWE 619 In Class Exercise Number 1A
Consider the following specification and implementation:
public static List<Integer> tail (List<Integer> list) {
// REQUIRES: ???
// EFFECTS: ???
List<Integer> result = new ArrayList<Integer>(list);
result.remove(0);
return result;
}
-
Can you explain the generics? What do you think of the copy constructor? What
are possible alternatives, and are they better or worse?
- What does the implementation of
tail
do in each of the following cases?
How do you know: Running the code or reading an API description?
list = null
list = []
list = [1]
list = [1, 2, 3]
- Write a partial specification that matches the "happy path" part of the implementation's behavior.
- Rewrite the specification to be total.
Use Bloch's standard exceptions.
- The resulting specification has a problem. What is it?
- Rewrite the specification to address this problem.
Rewrite the code to match the new specification.