This product is not supported for your selected Datadog site. ().
이 페이지는 아직 영어로 제공되지 않습니다. 번역 작업 중입니다. 현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.
Metadata
ID:java-best-practices/array-is-stored-directly
Language: Java
Severity: Notice
Category: Best Practices
Description
In Java, it is recommended that constructors and methods clone any arrays received through parameters. This practice prevents the original array from being affected by any future changes made by the caller.
It is advisable to clone the array before storing it to ensure that you retain a copy of the array that will remain unaffected by any external changes made to the original array. By following this approach, you can promote code safety and maintain the integrity of the original array.
Non-Compliant Code Examples
publicclassFoo{privateString[]x;privateinty;publicFoo(String[]param1,intparam2){this.x=param1;// should make a copy of this array first}}
publicclassFoo{privateint[]x;privateinty;publicvoidfoo(int[]param1,intparam2){this.x=param1;// should make a copy of this array first}}
publicclassFoo{privateString[]x;privateinty;publicvoidfoo(String[]param1,intparam2){this.x=param1;// should make a copy of this array first}}