The inherited method Method cannot be reflected and will be enforced by the compiler. Therefore, the method of the parent class is not considered when reflecting the method of a class, only the method of the current class is considered
Class.getMethod(String name,Class…parameterTypes); According to the method name and related parameters, locate the Method object that needs to be searched and return, parameterTypes: a list of Method parameter types (the order of parameters should be arranged according to the parameter list when the Method is declared)
Class.getMethods(); Get all public methods, including public methods declared by the class itself, public methods in the parent class, and implemented interface methods
Class.getDeclaredMethod(String name, Class... parameterTypes); returns a Method object reflecting the specified declared method of the class or interface represented by this Class object
Class.getDeclaredMethods(); Get all the methods in this class, including the methods of the class itself, the methods of the overridden parent class, and the implemented interface methods
2. Test cases
publicclassUser{
publicint id;private String name;
String address;protectedint sno;publicUser(){
}publicUser(int id, String name, String address,int sno){
super();this.id = id;this.name = name;this.address = address;this.sno = sno;}publicvoidstudy(){
System.out.println("study...");}publicvoideat(int a,String b){
System.out.println("eat...");}@Overridepublic String toString(){
return"User [id="+ id +", name="+ name +", address="+ address +", sno="+ sno +"]";}@OverridepublicinthashCode(){
finalint prime =31;int result =1;
result = prime * result +((address == null)?0: address.hashCode());
result = prime * result + id;
result = prime * result +((name == null)?0: name.hashCode());
result = prime * result + sno;return result;}@Overridepublicbooleanequals(Object obj){
if(this== obj)returntrue;if(obj == null)returnfalse;if(getClass()!= obj.getClass())returnfalse;
User other =(User) obj;if(address == null){
if(other.address != null)returnfalse;}elseif(!address.equals(other.address))returnfalse;if(id != other.id)returnfalse;if(name == null){
if(other.name != null)returnfalse;}elseif(!name.equals(other.name))returnfalse;if(sno != other.sno)returnfalse;returntrue;}}