我有这个代码:
public void onPlayerInteract(PlayerInteractEvent event) {
final Action action = event.getAction();
if (action == Action.LEFT_CLICK_BLOCK){
Location l1 = event.getClickedBlock().getLocation();
} else if (action == Action.RIGHT_CLICK_BLOCK) {
Location l2 = event.getClickedBlock().getLocation();
}
Thread t = new Thread() {
@Override
public void run() {
while(true) {
try {
Thread.sleep(1000*60*60);
//Insert code here
} catch (InterruptedException ie) {
}
}
}
};
t.start();
如何从//在此处插入代码
访问l1
?
最佳答案
只需在 if
block 之外声明 l1
,否则它是该 block 的本地变量。
关于java - 如何访问 if block 内声明的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10761928/