Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingOther conceptsAnnotations

Detecting annotations

Annotated fields

Report a typo

Implement the getFieldsContainingAnnotations method that lists the names of the fields declared in the object. The list should include all the fields containing at least one annotation. Fields inherited from parent classes should be omitted.

Write a program in Java 17
import java.lang.reflect.*;

/**
Get an array of fields the object declares that contain annotations (inherited fields should be skipped).
*/
class AnnotationsUtil {

public static String[] getFieldsContainingAnnotations(Object object) {
// Add implementation here
}

}
___

Create a free account to access the full topic