how to get the constant defined in the interface to which the method belongs in the method of the interface implementation class;
public interface RequireValidator {
Integer errno = 456;
Boolean required();
}
public interface TypeValidator {
Integer errno = 123;
Boolean isInteger();
}
public class Validator implements RequireValidator, TypeValidator {
@Override
public Boolean require() {
// 456
return null;
}
@Override
public String isInteger() {
// 123;
return null;
}
}
as above, how do I get the corresponding value at the comment? ask for answers!
my idea is as follows:
- get all the interfaces implemented by the class;
- iterate through the list of interfaces to find the interface that defines the method;
- then directly access
errno
; through the identified interface.
is how to determine whether the interface defines the current method?
there is a better way to achieve, please point out, I rookie, ask for help!