Can I use something like @MagicConstant to restrict a string paramter to field names of a certain class?

Suppose I have a class

class Scratch {
public String name;
public int age;

public static void reflectiveAccess(Scratch scratch, String fieldName) {

}
}

 

Can I use something like @MagicConstant to get code completion to suggest the string literals "name" and "age"?

Ideally, IntelliJ would also warn on string literals that are wrong like "fieldDoesNotExist"

Please sign in to leave a comment.