Java Reflection - Attributes

  • + 0 comments

    The below code passed the test when run in Java 7 but not in Java 15 environment. Why? I cannot understand the reason? Is this just a bug?

    public class Solution { public static void main(String[] args) { Class student = Student.class;

        Method[] methods = student.getDeclaredMethods(); 
    
        ArrayList<String> methodList = new ArrayList<>();
        for (Method method : methods) {
            methodList.add(method.getName()); 
        }
    
        Collections.sort(methodList); 
        for (String name : methodList) {
            System.out.println(name); 
        }
    }
    

    }