Javac missing optimization for effective final
问题 Fact: javac is programmed to detect if a variable is final or if it can be treated as effectively final . Proof: This code illustrates this. public static void finalCheck() { String str1 = "hello"; Runnable r = () -> { str1 = "hello"; }; } This fails to compile because compiler is able to detect String reference str1 is being re-assigned in function. Now Situation 1: Javac does great optimization for final String instances by avoiding to create StringBuilder and related operations. Proof This