How to create new variable in java dynamically

前端 未结 6 1247
闹比i
闹比i 2020-12-06 15:08

Is it possible to create new variables in java dynamically.

class A {
methodA(String variableName) {

      }
}

So if new method is called

6条回答
  •  抹茶落季
    2020-12-06 15:28

    No, this is not possible to do in Java.

    The fields in a class is determined at compile time and can't be changed during runtime (except though sophisticated techniques such as class reloading though for instance JRebel). I would however not recommend doing this, unless you're writing some IDE for instance.

提交回复
热议问题