groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Søren Martin Kristensen <smk.kristen...@gmail.com>
Subject the groovy *= operator differs in behaviour from that of java
Date Mon, 27 Jun 2016 11:38:48 GMT
Hello

I have just realized that *= differs in behaviour between groovy and java.
The following source snipletsreturns 7 and 0 for groovy and java,
respectively. However, I could not find any description of this in the list
of differences between the two languages on
http://www.groovy-lang.org/differences.html

//groovy:
int a = 35;
int b = 20;
a *= b/100;
println a;

This script returns 7

//java:
public class test_multiply_operator {
  public static void main(String[] args) throws Exception {
    int a = 35;
    int b = 20;
    a *= b/100;
    System.out.println(Integer.toString(a));
  }
}

This java program returns 0. This is because java evaluates the right-hand
expression before multiplication.

In case I have not missed something, I guess this would be nice to have on
the list of differences between the two languages.

Best regards,
Søren
--

Mime
View raw message