Reputation: 7844
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?
Upvotes: 0
Views: 67
Reputation: 1872
write new method and move this operation into it.
ex :
private void splitTest() {
test.split("something");
}
Upvotes: 0
Reputation: 240966
statement
test.split("something");
should be in executable block (method/ constructor/ static initilization blocks)
Upvotes: 6