How to pass varargs by reference in Java

前端 未结 6 1278
青春惊慌失措
青春惊慌失措 2021-01-29 03:53

I\'m writing a method that receives any number of arguments and returns them modified. I have tried with varargs but it doesn\'t work, here you can see a simplified version of t

6条回答
  •  轮回少年
    2021-01-29 04:30

    You can't do it.

    Change the method signature as List, then, you can expect this pass-by-reference behavior. Here, you are passing each argument individually, and java makes them as array internally and to the processing further.

提交回复
热议问题