I need a way to get a list of all methods of a java class which could be called from a java file. I know that I can use Class.getMethods
, but that does not work in some situations like I need it:
public interface IField<T> {
public void setValue(T value);
}
public class Field implements IField<String> {
private String value;
@Override
public void setValue(String value) {
this.value = value;
}
}
Calling Field.class.getMethods()
contains to setValue
methods, but only the one with the String
parameter is allowed to be called from a java source file.
Just remove the one with the "less specific" parameter is also not a solution becasue there might be situations like this:
public abstract class AbstractBean {
private Object value;
public void setValue(Object value) {
this.value = value;
}
}
public class Field extends AbstractBean {
private Integer value;
public void setValue(Integer value) {
this.value = value;
};
}
where both setValue
methods are ok to be called.
Aucun commentaire:
Enregistrer un commentaire