Why is it that in 1.3 and 1.4 final variables that are copied to an inner class are copied after initialization but in 1.5 it suddenly moved to before initialization? This came up as a result of this thread and I'm curious to know if anyone has any ideas. I've found the Sun forums have far more arrogance than they do actual knowledge and most of the intelligent posters are from Javaranch anyway so I'm asking here.
Compiled in 1.4:
Compiled in 1.5:
EDIT: Disabled smilies. [ December 15, 2005: Message edited by: Ken Blair ]
I don't have any actual knowledge about that. I looked at the "what's new in Java 5" documents and couldn't find the word "final". Perhaps it's a bug fix? I couldn't find it in the bug database (my search for "final inner" returned about 10,000 results) but anyway, it certainly sounds like an improvement to me. I remember struggling against that problem back in Java 1.3 days and having to do some horrible workaround (as I classified it then).
Yes, it definitely sounds like a JSR-133 thing. One of the major concerns there was ensuring that there was no way for some threads to observe final fields changing their values, which could occasionally happen in earlier Java versions. This is achieved by making sure those fields are initialized before any reference to the constructed oject is allowed to escape for use or abuse by any threads other than the one performing construction. Bill Pugh's page has a nice JSR-133 FAQ covering this and other issues. [ December 15, 2005: Message edited by: Jim Yingst ]