SWE 619 In Class Exercise # 1B


Goal: Understanding Contracts
Consider the Java Iterator interface.

Focus attention on the three main methods: next(), hasNext(), and remove(). Ignore the default method.

For each method, identify all preconditions and postconditions. For each precondition, identify a specific input that violates the precondition. For each postcondition, identify an input specific to that postcondition.

You should think about "inputs" as concrete executions or test cases. For example:

    List<String> list = ...   // [cat, dog]
    Iterator<String> itr = list.iterator(); 
    itr.hasNext()       // postcondition says this should return "true"
    itr.remove()        // postcondition says this should throw ISE