defensive copy 中文意思是什麼

defensive copy 解釋
保護性拷貝
  • defensive : adj. 1. 防衛的,防禦的;守勢的。2. 辯護的。n. 1. 守勢。2. 辯護。adv. -ly ,-ness n.
  • copy : n 1 抄本,繕本,謄本,摹本,復製品,【電影】拷貝;【法律】副本 (opp script)。2 (書的)一部,一...
  1. Given that so few classes actually include such documentation, the safe strategy when calling a method that doesn t document its call semantics or side - effect behavior is to create a defensive copy before passing it to any such method. ironically, the performance benefit of the decision to make

    因為很少有類真正包含這樣的文檔,所以在調用一個沒有用文檔說明其調用語義或副作用行為的方法時,安全的策略是在傳遞它到任何這樣的方法之前創建一份防禦副本。
  2. There may be a cost to making defensive copies when passing an array reference to another class, but unless you are sure that the other class either makes its own copy or that it will not hold the reference for longer than the duration of the call, you probably want to make a copy before passing the array

    當傳遞一個數組引用到另一個類時,可能有創建防禦副本的代價,除非您能確保其他類要麼創建了它自己的副本,要麼只在調用期間保存引用,否則您可能需要在傳遞數組之前創建副本。
分享友人