Compile Time Evaluation: constexpr for Java

Brian Goetz brian.goetz at oracle.com
Wed Jan 13 21:56:44 UTC 2021



> Since the const keyword is not used in Java can this be operposed for 
> compile time evaluation? Classes, interfaces, methods, fields marked 
> with const will only be available at compile time and would be fully 
> evaluated and replaced with the results in runtime bytecode.

Better support for compile-time constant folding is a laudable goal (see 
https://www.youtube.com/watch?v=iSEjlLFCS3E for an exploration of just 
some of the issues involved).  But coming up with a useful, powerful, 
and consistent mechanism for exposing compile-time constant folding and 
propagation requires a lot more than "let's use keyword X."  I think if 
you try to flesh this out to the next few levels, you'll find that there 
are many possible paths here, and choosing between them is not trivial.

Suffice it to say that we agree that there are opportunities to expose 
better constancy, but picking a keyword to slap on fields and methods is 
not the hard part.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20210113/5999e812/attachment.htm>


More information about the compiler-dev mailing list