Why there is no local static variable in Java?

前端 未结 5 1866
星月不相逢
星月不相逢 2020-12-06 04:47

In C/C++ we use static local variables for maintaining a method\'s state. But why it is not supported in Java?

Yes, I can use an static field for this purpose. But i

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 05:15

    Perhaps because methods are not objects in Java; so maintaining their state as you said make not much sense and I guess you'd have to create a new concept in the byte code for that; use an object as Tony K. said.

提交回复
热议问题