当我运行这段代码时答案是1,我认为它将是2.初始化的顺序和每一步中k的值是多少?
public class Test {
static {k = 2;}
static int k = 1;
public static void main(String[] args) {
    System.out.println(k);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑1:作为"k设置为默认值"的后续内容,为什么下一个代码不能编译?这是一个错误"无法在定义之前引用字段".
public class Test {
static {System.out.println(k);}
static int k=1;
public static void main(String[] args) {
    System.out.println(k);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑2:对于一些我不知道的原因,当^而不是"k"它的"Test.k"时它起作用.
感谢所有的答案.这将是完美的:D
我想使用XPath(在Java中)从下面的snipet中仅选择文本"only this text",但该文本是随机的,我不知道那里写的是什么.
 <div class="A">
    <input id="button" type="button">x</input>
    only this random text
 </div>
Run Code Online (Sandbox Code Playgroud)
什么是最简单的xpath?
 //div[@class='A'][what next?]
Run Code Online (Sandbox Code Playgroud)
我看到类似的问题,但答案总是太复杂,我想知道最简单的方法.
还有没有其他方法,没有使用XPath(在Java中)来获取该文本?
谢谢.