0
public class SomeClass {
  //Some code
  private static InnerClass {
    String test;
    private InnerClass(String test) {
      this.test = test;
    }

    // Using test here in some way
    test.split("something"); //Compiler error, test might not have been initialized
}

Why does the compiler complain about that? I am initializing test in the constructor. If the compiler is complaining, that means there might be a way to access test without going through the constructor. I tried that, but no luck without reflection. What am I missing here?

4

2 回答 2

6

陈述

 test.split("something");

应该在可执行块中(方法/构造函数/静态初始化块)

于 2013-07-29T16:06:36.980 回答
0

编写新方法并将此操作移入其中。

前任 :

private void splitTest() {
test.split("something");
}
于 2013-07-29T16:53:52.333 回答