Field count

Report a typo

Implement the getNumberOfAccessibleFields method to count the number of accessible public fields of the class or interface represented by the clazz object.

Write a program in Java 17
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;

/**
Get number of accessible public fields for a given class.
*/
class FieldGetter {

public int getNumberOfAccessibleFields(Class<?> clazz) {
// Add implementation here
}

}
___

Create a free account to access the full topic