/* * Created on Jul 25, 2006 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package cu.misc; public class FinalBug { // correctly passes compilation static class Test1 { private final Object o; Test1() { o = new Object(); } } // correctly passes compilation static class Test2 { private final Object o; Test2() { this.o = new Object(); } } // correctly fails compilation static class Test3 { private final Object o; Test3() { System.out.println(o); // illegal; o is not definitely assigned o = new Object(); } } // correctly passes compilation static class Test4 { private final Object o; Test4() { System.out.println(this.o); // legal o = new Object(); } } // incorrectly passes compilation static class Test5 { private final Object o; Test5() { Test5 other = this; other.o = new Object(); // illegal! other.o is not assignable } // error: this.o is not definitely assigned } // flags wrong statement as error static class Test6 { private final Object o; static Test6 initing; Test6() { initing = this; System.out.println("greetings"); Test6 other = initing; other.o = new Object(); // illegal! other.o is not assignable o = new Object(); // legal } } }