Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

compiler optimisation  RSS feed

 
George Brown
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following two noddy classes:

and

so when you type 'java B' the output will be 'banana'.
I know that the compiler will optimise the bytecode so that once the two classes have been compiled, and you change the value of the 'fruit' variable in A to "pineapple", recompiling A will not change the output of the B class. Fine, so it's copied at compile time as an optimisation feature. No problem there.
However, I am looking at the java.sun.com site to find out where this compiler feature has been documented, and though I have looked at the JLS and the JVMS I cannot find a reference to it.
Does anyone know whether sun have documented this, or maybe provided warnings about it? I've certainly read stuff about it in the past but I really need it from the horse's mouth so to speak.
Any replies are much appreciated.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From JLS 13.4.8:
If a field is a compile-time constant, then deleting the keyword final or changing its value will not break compatibility with pre-existing binaries by causing them not to run, but they will not see any new value for the constant unless they are recompiled.

They go on with further examples and discussion.
 
George Brown
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jim
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!