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

Jochen Theodorou commented on GROOVY-11287:
-------------------------------------------

I agree with [~emilles] that the context we are doing the inlining in would 
have to be @CompileStatic. the source can be a not static compiled source 
actually. Java is doing that imho for all operations using operators (+-*/) 
based on numbers, maybe chars and Strings. Sources must be constant contexts

> Perform constant folding for basic math calculations in CS
> ----------------------------------------------------------
>
>                 Key: GROOVY-11287
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11287
>             Project: Groovy
>          Issue Type: New Feature
>          Components: performance, Static compilation
>            Reporter: Oscar N
>            Assignee: Eric Milles
>            Priority: Major
>
> I have the following Groovy code and its Java equivalent:
> {code:groovy}
> @CompileStatic
> final class Main {
>     private static final int ONE = 1
>     static void main(String[] args) {
>         int two = ONE + 1
>         println two
>     }
> }
> {code}
> {code:java}
> public final class JavaMain {
>     private static final int ONE = 1;
>     public static void main(String[] args) {
>         int two = ONE + 1;
>         System.out.println(two);
>     }
> }
> {code}
> In Groovy, it currently compiles to:
> {code}int two = ONE + 1{code}
> In Java, the calculation is done at compile-time and inlined:
> {code}int two = 2{code}
> It would be great if Groovy also did this.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to