Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.7.2
-
Fix Version/s: None
-
Component/s: groovy-jdk
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
The script
Deque stack = new LinkedList() stack.push(1) stack.push(2) assert stack.peek() == 2
fails.
Reason: java.util.LinkedList implements both java.util.List and java.util.Deque. DGM implements push(T) as add(T), and pop() as remove(size() - 1) for java.util.List. However, for Deque push(T) must be equivalent to addFirst(T), and pop() must be equivalent to removeFirst().
Ref.:
http://old.nabble.com/Using-Deque-in-groovy-to28345878.html
http://java.sun.com/javase/6/docs/api/java/util/Deque.html
We should check what other languages (e.g. Ruby) does for non-Deque like lists - flipping both push and pop would have no change visible change to new items pushed and popped - but reverses the order of any initial items. Certainly just defaulting back to the original methods fixes the Deque behavior.