[ 
https://issues.apache.org/jira/browse/GROOVY-6396?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15500249#comment-15500249
 ] 

ASF GitHub Bot commented on GROOVY-6396:
----------------------------------------

Github user jwagenleitner commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/419#discussion_r79297442
  
    --- Diff: src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java ---
    @@ -8928,6 +8932,27 @@ public int compare(Map.Entry<K, V> e1, Map.Entry<K, 
V> e2) {
             if (self.isEmpty()) {
                 throw new NoSuchElementException("Cannot pop() an empty List");
             }
    +        return self.remove(0);
    +    }
    +
    +    /**
    +     * Removes the last item from the List. Using add() and pop()
    +     * is similar to push and pop on a Stack.
    +     * <pre class="groovyTestCase">
    +     * def list = ["a", false, 2]
    +     * assert list.removeLast() == 2
    +     * assert list == ["a", false]
    +     * </pre>
    +     *
    +     * @param self a List
    +     * @return the item removed from the List
    +     * @throws NoSuchElementException if the list is empty and you try to 
pop() it.
    +     * @since 2.5.0
    +     */
    +    public static <T> T removeLast(List<T> self) {
    +        if (self.isEmpty()) {
    +            throw new NoSuchElementException("Cannot pop() an empty List");
    --- End diff --
    
    `pop()` -> `removeLast()`


> same linkedlist code different behavior between groovy and java
> ---------------------------------------------------------------
>
>                 Key: GROOVY-6396
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6396
>             Project: Groovy
>          Issue Type: Bug
>          Components: jdk conflict
>            Reporter: boshi 
>              Labels: breaking
>
> I am using `linkedlist` as a stack in groovy 
> as doc says, `pop()` take elm from the first
>     Stack Method  Equivalent Deque Method  
>     push(e)       addFirst(e) 
>     pop()         removeFirst()
> so a `linkedlist` [1,2,3] should pop() 1 2 3
> and it does in Java, but does NOT in groovy. WHY?
> test below
> {code:title=A.java}
> import java.util.*;
>     
> public class A{
>     
>     
>     public static void main(String[] args){
>     
>         String[] x = "1/2/3/".split("/");
>         LinkedList <String> stack = new LinkedList<String>(Arrays.asList(x));
>         System.out.println(stack.pop());
>     }
> }
> {code}
> compile and run
> {noformat}
> $ javac A.java
> $ java A
> 1
> {noformat}
> runing in groovy
> {noformat}    
> $ ln -s A.java A.groovy
> $ groovy A.groovy
> 3
> {noformat}
> here is my java and groovy version
> {noformat}
> $ java -version
> java version "1.6.0_51"
> Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)
> Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)
> $ groovy -version
> Groovy Version: 2.1.5 JVM: 1.6.0_51 Vendor: Apple Inc. OS: Mac OS X
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to