-
Bug
-
Resolution: Unresolved
-
P4
-
repo-amber
-
Fix Understood
-
generic
-
generic
Given:
public class X {
private static int get42() {
return 42;
}
X() {
this(get42());
}
X(int x) {
}
}
The finder recommends that get42() can be local to X()
If you move it in as a local method, it has to lose its private and static modifiers and the code would look like
(the only modifiers accepted in a local method is final)
public class X {
X() {
int get42() {
return 42;
}
this(get42());
}
X(int x) {
}
}
This presently triggers: X.java:8: error: call to this must be first statement in constructor.
Javac should allow local methods above this()/super() call, implicitly forcing them to be static.
public class X {
private static int get42() {
return 42;
}
X() {
this(get42());
}
X(int x) {
}
}
The finder recommends that get42() can be local to X()
If you move it in as a local method, it has to lose its private and static modifiers and the code would look like
(the only modifiers accepted in a local method is final)
public class X {
X() {
int get42() {
return 42;
}
this(get42());
}
X(int x) {
}
}
This presently triggers: X.java:8: error: call to this must be first statement in constructor.
Javac should allow local methods above this()/super() call, implicitly forcing them to be static.