Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7937

CLONE - same linkedlist code different behavior between groovy and java (fix priority of DGM methods vs actual methods on an object)

    XMLWordPrintableJSON

Details

    Description

      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

      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());
          }
      }
      

      compile and run

      $ javac A.java
      $ java A
      1
      

      runing in groovy

          
      $ ln -s A.java A.groovy
      $ groovy A.groovy
      3
      

      here is my java and groovy version

      $ 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
      

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              farmer1992 boshi
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: