Where does return value go in java if no variable assigned to accept it?

后端 未结 4 521
南方客
南方客 2021-01-07 03:17

Let\'s say a method returns some value, but when I call it, I don\'t assign any variable to accept this RV. Then where does it go? Will GC collect it? Would it be a problem

4条回答
  •  悲&欢浪女
    2021-01-07 03:21

    Will GC collect it?

    Yes. Since there would be no live reference to the Object returned it would be eligible for GC.

    Would it be a problem if I use this kind of method tons of times in my code?

    It should not. All the returned Objects will be GCed.

提交回复
热议问题