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;
}
  1. Can you explain the generics? What do you think of the copy constructor? What are possible alternatives, and are they better or worse?

  2. 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]

  3. Write a partial specification that matches the "happy path" part of the implementation's behavior.

  4. Rewrite the specification to be total. Use Bloch's standard exceptions.

  5. The resulting specification has a problem. What is it?

  6. Rewrite the specification to address this problem. Rewrite the code to match the new specification.