Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 10BDD200B94 for ; Sun, 18 Sep 2016 06:44:23 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 0F8D2160ACD; Sun, 18 Sep 2016 04:44:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 01E15160AD6 for ; Sun, 18 Sep 2016 06:44:21 +0200 (CEST) Received: (qmail 13464 invoked by uid 500); 18 Sep 2016 04:44:21 -0000 Mailing-List: contact notifications-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list notifications@groovy.apache.org Received: (qmail 13360 invoked by uid 99); 18 Sep 2016 04:44:20 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Sep 2016 04:44:20 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id C04632C0D57 for ; Sun, 18 Sep 2016 04:44:20 +0000 (UTC) Date: Sun, 18 Sep 2016 04:44:20 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: notifications@groovy.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (GROOVY-6396) same linkedlist code different behavior between groovy and java MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sun, 18 Sep 2016 04:44:23 -0000 [ https://issues.apache.org/jira/browse/GROOVY-6396?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15500246#comment-15500246 ] 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_r79297434 --- Diff: src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java --- @@ -8928,6 +8932,27 @@ public int compare(Map.Entry e1, Map.Entry 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. + *
    +     * def list = ["a", false, 2]
    +     * assert list.removeLast() == 2
    +     * assert list == ["a", false]
    +     * 
+ * + * @param self a List + * @return the item removed from the List + * @throws NoSuchElementException if the list is empty and you try to pop() it. --- End diff -- I think `if the list is empty` suffices here and don't think the rest of the sentence is needed (same for `pop` throws). > 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 stack = new LinkedList(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)