Goals: (A) (more) Identifying preconditions and postconditions in common Java contracts, and (B) Basic JUnit tests.
A: Consider the following excerpt from the JavaDoc specification from
Note: Great care must be exercised if mutable objects are used as set elements. The behavior of a set is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is an element in the set. A special case of this prohibition is that it is not permissible for a set to contain itself as an element.
Stackobjects are mutable.
Set<Stack<String>> set = new HashSet<Stack<String>>(); // Line 1 Stack<String> stack1 = new Stack<String>(); // Line 2 Stack<String> stack2 = new Stack<String>(); // Line 3 stack1.push("cat"); // Line 4 set.add(stack1); // Line 5 set.add(stack2); // Line 6 stack2.push("cat"); // Line 7What is the state after each line of code?
Which line(s) of code, if any, are in conflict with the JavaDoc specification?
Relation to course outcomes:
Demonstrate knowledge of how to apply object-oriented specification and analysis techniques to Java.