Java Reflection - Attributes

  • + 0 comments
    public class Solution {
    
            public static void main(String[] args){
                Student st = new Student();
                Class student = st.getClass();
                Method[] methods = student.getDeclaredMethods();
    
                ArrayList<String> methodList = new ArrayList<>();
                for(int m = 0; m < methods.length; m++){
                    methodList.add(methods[m].getName());
                }
                Collections.sort(methodList);
                for(String name: methodList){
                    System.out.println(name);
                }
            }
    
        }