Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: Assumed final? Date: Mon, 30 Jun 2014 10:28:35 -0700 Organization: A noiseless patient Spider Lines: 48 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 30 Jun 2014 17:28:34 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="aba33539224e5c782fe0c4053f7756fd"; logging-data="14381"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hV8VOneT/kVcwMqkAKJo/" User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 Cancel-Lock: sha1:6Yc2syu3IJF7+suAmLg97QBosSQ= Xref: csiph.com comp.lang.java.programmer:28877 I always thought the code below would have generated a error on compile that frame wasn't final. But I see when I compile it now with JDK 8 that there is no error unless I make another assignment to frame. If I uncomment the frame = null; statement, then I get the error; C:\Users\Knute Johnson>javac test9.java test9.java:17: error: local variables referenced from an inner class must be final or effectively final frame.dispose(); ^ 1 error So it appears that the Java 8 compiler has gotten smarter or I haven't been paying enough attention :-). import java.awt.*; import java.awt.event.*; import javax.swing.*; public class test9 extends JPanel { public test9() { setPreferredSize(new Dimension(320,180)); setBackground(Color.BLUE); } public static void main(String... args) { EventQueue.invokeLater(new Runnable() { public void run() { JFrame frame = new JFrame("test9"); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { frame.dispose(); } }); frame.add(new test9(),BorderLayout.CENTER); frame.pack(); frame.setVisible(true); //frame = null; } }); } } -- Knute Johnson