如何在java中动态创建新变量 [英] How to create new variable in java dynamically

查看:1383
本文介绍了如何在java中动态创建新变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以动态地在java中创建新变量。

Is it possible to create new variables in java dynamically.

class A {
methodA(String variableName) {

      }
}

因此,如果两次调用新方法,那么应该在这个类中新添加2个新变量?

So if new method is called twice, 2 new variables should be newly added to this class?

有可能吗?

推荐答案

没有。您是否考虑在课程中存储 Map< String,Object> ?地图中的键将是变量名称,地图中的值将是逻辑变量名称。

No. Have you considered storing a Map<String, Object> in the class instead? The keys in the map would be the "variable names" and the values in the map would be the logical variable names.

如果您可以提供有关您的信息的更多信息重新尝试(从高层次来看)这将有所帮助。

If you could give more information about what you're trying to achieve (from a high-level perspective) that would help.

这篇关于如何在java中动态创建新变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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