Can I detect whether I've been given a new object as a parameter?

前端 未结 9 602
日久生厌
日久生厌 2021-01-18 01:31

Short Version

For those who don\'t have the time to read my reasoning for this question below:

Is there any way to enforce a policy of "new obje

9条回答
  •  无人共我
    2021-01-18 02:04

    Nope, there's no way of knowing.

    All that gets passed in is the object reference. Whether it is 'newed' in-situ, or is sourced from an array, the method in question has no way of knowing how the parameters being passed in have been instantiated and/or where.

提交回复
热议问题