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 Re: the groovy *= operator differs in behaviour from that of java
Date Tue, 05 Jul 2016 23:20:00 GMT
That's right. This behaviour has actually confused me before, as I do most
developement in plain java. Thanks, I appreciate your help.

On Mon, Jun 27, 2016 at 2:00 PM, Marshall, Simon <Simon.Marshall@misys.com>
wrote:

> I imagine it’s due to b/100 being a BigDecimal.  See
> http://www.groovy-lang.org/syntax.html#integer_division.
>
>
>
> *From:* Søren Martin Kristensen [mailto:smk.kristensen@gmail.com]
> *Sent:* 27 June 2016 12:39
> *To:* users@groovy.apache.org
> *Subject:* the groovy *= operator differs in behaviour from that of java
>
>
>
> 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
>
> --
> "Misys" is the trade name of the Misys group of companies. This email and
> any attachments have been scanned for known viruses using multiple
> scanners. This email message is intended for the named recipient only. It
> may be privileged and/or confidential. If you are not the named recipient
> of this email please notify us immediately and do not copy it or use it for
> any purpose, nor disclose its contents to any other person. This email does
> not constitute the commencement of legal relations between you and Misys.
> Please refer to the executed contract between you and the relevant member
> of the Misys group for the identity of the contracting party with which you
> are dealing.
>



-- 
Søren Martin Kristensen
Klostergårdsvej 13
DK 3500 Værløse

Mime
View raw message