好的,这是一个关于java的新手问题,但我似乎无法理解它.
我班上有以下代码
private static final String [] LIST_CODE = gerarListCode();
private static final int [][] LIST_INTEGER = new int [][] {
{947,947}, {110,103},
{947,958}, {110,120},
{947,954}, {103,107},
{947,967}, {110,99,104}};
private static String [] gerarListCode()
{
String [] listCode = new String [LIST_INTEGER.length];
for (int i=0 ; i<LIST_INTEGER.length ; i++)
{
//do some stuff
}
return listaUnicode;
}
Run Code Online (Sandbox Code Playgroud)
由于以下行中的nullpointerexception,此代码给出了初始化异常
String [] listCode = new String [LIST_INTEGER.length];
Run Code Online (Sandbox Code Playgroud)
似乎那时变量LIST_INTEGER为null.
有人可以解释原因吗?是类加载器进程是线性的,换句话说,它是在完全加载所有其他变量之前调用方法吗?
我对所有扩展抽象类的子类使用依赖项注入。
在抽象构造函数类中,如果需要的话,我启动了一个计划在其子级中覆盖的方法。
我陷入了一个问题,即从super启动的重写类中看不到注入的依赖项。
这是代码示例:
abstract class Base {
constructor(view: string) {
this._assemble();
}
protected _assemble(): void {
console.log("abstract assembling for all base classes");
}
}
class Example extends Base {
constructor(view: string, private helper: Function) {
super(view);
console.log(this.helper);
}
public tryMe(): void {
this._assemble();
}
protected _assemble(): void {
super._assemble();
// at first run this.helper will be undefined!
console.log("example assembling", this.helper);
}
}
let e = new Example("hoho", function () { return; })
console.log("So now i will try to reassemble..."); …Run Code Online (Sandbox Code Playgroud)