如何访问if-block中声明的变量?

Tho*_*eia 0 java variables

我有这个代码:

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();
Run Code Online (Sandbox Code Playgroud)

如何访问l1//insert code here

Gen*_* S. 7

只需l1if块外声明,否则它是该块的本地.