有没有办法让Java类了解其实例化器?例如:
public class Foo() {
public Foo() {
// can I get Bar.myInteger from here somehow
// without passing it in to the constructor?
}
}
public class Bar {
private int myInteger;
public Bar() {
myInteger = 0;
Foo foo = new Foo();
}
}
Run Code Online (Sandbox Code Playgroud)
有了内部课程,你可以.
public class Bar {
private int myInteger;
public class Foo() {
public Foo() {
// you can access myInteger
}
}
public Bar() {
myInteger = 0;
Foo foo = new Foo();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
297 次 |
| 最近记录: |