- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: java-best-practices/avoid-reassigning-parameters
Language: Java
Severity: Warning
Category: Code Style
Avoid reassigning values to method parameters as it can make the code harder to understand. Typically, parameter values are expected to remain unchanged throughout the method’s execution, and any reassignment might be not be noticed by other developers.
We consider it acceptable to reassign parameters in small functions, smaller than 20 lines. Otherwise, consider using temporary local variables with clear naming to enhance code readability.
public class Person {
private void greet(String name) {
System.println("this is a long method");
System.println("this is a very long method");
name = name.trim(); // reassigning parameter value
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
System.println("this is a long method");
}
}
public class Main {
public static void subscribeResult(
@Advice.Enter final int callDepth,
@Advice.Origin final Method method,
@Advice.FieldValue("bucket") final String bucket,
@Advice.Return(readOnly = false) Observable result) {
if (callDepth > 0) {
return;
}
CallDepthThreadLocalMap.reset(CouchbaseCluster.class);
result = Observable.create(new CouchbaseOnSubscribe(result, method, bucket));
}
}
public class Main {
private static void addStrSegment(List<LogProbe.Segment> segments, String str) {
str = Strings.replace(str, "{{", "{");
str = Strings.replace(str, "}}", "}");
segments.add(new LogProbe.Segment(str));
}
}
public class Person {
private void greet(String name) {
String trimmedName = name.trim();
}
}