List private fields

Report a typo

Implement getPrivateFields method to list the names of private fields declared in the class the object belongs to. Fields inherited from parent classes should be omitted. Field names should be sorted in lexical order.

Here we use List<String> since it's more appropriate for the task. Check out the docs if you're not familiar with it.

Write a program in Java 17
import java.util.List;

/**
Get sorted list of private fields the object declares (inherited fields should be skipped).
*/
class FieldGetter {

public List<String> getPrivateFields(Object object) {
// Add implementation here
}

}
___

Create a free account to access the full topic