
ReflectionParameter 클래스의 getAttributes 메소드는 ReflectionParameter 객체에서 Attribute를 가져올 수 있는 메소드입니다. Attribute는 클래스, 메소드, 필드에 대한 추가적인 정보를 담고 있습니다. 예를 들어, Attribute를 사용하여 메소드의 파라미터 이름, 타입, 필드의 이름, 타입을 가져올 수 있습니다.
ReflectionParameter 객체에서 Attribute를 가져올 수 있는 방법은 다음과 같습니다.
1. ReflectionParameter 객체의 getAttributes 메소드를 호출하여 Attribute를 가져옵니다.
2. 가져온 Attribute를 반복문을 사용하여 각 Attribute의 이름, 타입, 값 등을 가져올 수 있습니다.
Attribute는 다음 종류의 정보를 담을 수 있습니다.
- 메소드 파라미터 이름, 타입
- 필드 이름, 타입
- 클래스 이름, 타입
- 메소드 이름, 반환 타입
예를 들어, 다음 코드에서는 ReflectionParameter 객체의 getAttributes 메소드를 호출하여 Attribute를 가져옵니다.
#hostingforum.kr
java
import java.lang.reflect.Parameter;
public class Main {
public static void main(String[] args) {
Method method = Main.class.getMethod("testMethod", String.class);
Parameter[] parameters = method.getParameters();
for (Parameter parameter : parameters) {
Attribute[] attributes = parameter.getAnnotations();
for (Attribute attribute : attributes) {
System.out.println(attribute.getName() + ": " + attribute.getType());
}
}
}
public static void testMethod(String param1) {
System.out.println("testMethod");
}
}
이 코드에서는 testMethod 메소드의 파라미터 이름, 타입을 가져옵니다. Attribute를 사용하여 클래스, 메소드, 필드에 대한 추가적인 정보를 가져올 수 있습니다.
2025-07-28 22:07