如何在Java中尝试更改变量? [英] How do I change a variable from a try in java?

查看:218
本文介绍了如何在Java中尝试更改变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我试图在try语句中更改变量的值,以便在try之外影响变量,有人知道怎么做吗?

Hey everyone, im trying to change the value of a variable from within a try statement so that it will effect the variable outside of the try, does anyone know how to do this?

推荐答案

try块(与任何其他语句块一样)可以访问外部块变量.另一方面,如果在try块本身内部定义变量,则无法在外部进行更改(例如,参见^ ]).
The try block (like any other block of statements) may access outer blocks variables. On the other hand if you define a variable inside the try block itself then you cannot change it outside (see, for instance here[^]).


这篇关于如何在Java中尝试更改变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆