Tuesday, August 10, 2010

illegal forware reference in java

case 1:  比較常見的
class Test {
  String s = "hello";

  class inner {
    inner () {
        String s = s;  // <- illegal forward reference
    }
  }
}


case 2:  比較特別的 即使sStr是static也會


class Test2 {
  static {
    System.out.println(sStr);  // <- illegal forward reference
  }

  private static String sStr = "hello World";
}

No comments: