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?

1
  • Is this your full code? Or you selected only parts of it? Commented Jul 29, 2013 at 16:16

2 Answers 2

6

statement

 test.split("something");

should be in executable block (method/ constructor/ static initilization blocks)

Sign up to request clarification or add additional context in comments.

Comments

0

write new method and move this operation into it.

ex :

private void splitTest() {
test.split("something");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.