你能在 Java 中获取变量的先前值吗? [英] Can you get the previous value of a variable in Java?

查看:31
本文介绍了你能在 Java 中获取变量的先前值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说 way 有一个变量(比如 String Str),Str 的值以"开头,然后当一些代码正在运行时,它被设置为test",然后在代码中的其他地方再次更改为测试员".现在在程序中我想找出 Str 的先前值是多少.这在 Java 中可行吗?

Say way have a variable (let's say String Str) and the value of Str starts of as " " then as some code is running it is set to "test" then somewhere else in the code it is changed again to say "tester". Now in the program I want to find out what the previous value of Str was. Is this possible in Java?

所以我是说变量被改变了两次,你想在它第二次改变之前找出 Str 是什么.因此,在上面的示例中,Str 的最新值将是tester",但我想找出 Str 在此之前是什么(假设您在更改为 tester 之前不知道它是什么)在这种情况下我想成为能够发现 Str 是测试".

So I am saying that the variable gets changed twice, and you want to find out what Str was before it got changed for the second time. So in the example above the latest value of Str would be "tester" but I wanted to find out what Str was before this (assuming you had no idea what it was before it was changed to tester) in this case I would want to be able to find out that Str was "test".

在 Java 中完全可以做到这一点吗?

Is it at all possible to do this in Java?

推荐答案

不,这是不可能的,您必须在更改之前保存先前的值以执行您的要求.

No, it's not possible, you have to save the previous value before you change it to do what you're asking for.

这篇关于你能在 Java 中获取变量的先前值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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