That is my code.why the reflect api return both methods?
I defined an interface,like this:
import java.util.List;
public interface Species<T> {
T feed(List<String> numList);
}
the Animal is the implement class of Species:
import lombok.Data;
import java.util.List;
@Data
public class Animal<T> implements Species<T> {
private T t;
@Override
public T feed(List<String> numList) {
return t;
}
}
the Dog class is a child of Animal class:
import java.util.List;
public class Dog extends Animal<String>{
@Override
public String feed(List<String> numList) {
return "dog feed method";
}
}
This is my test class,its:
public class TypeTest {
public static void main(String[] args) {
Class<Dog> dogClass = Dog.class;
Method[] declaredMethods = dogClass.getDeclaredMethods();
for(Method m:declaredMethods){
System.out.println(m.getReturnType().getName());
}
}
}
the run output:
java.lang.String
java.lang.Object
check the variable declaredMethods