Java Reflection - Attributes

Sort by

recency

|

112 Discussions

|

  • + 0 comments

    This test is broken.

  • + 0 comments

    Java 7 Solution:

    public class Solution {
    
            public static void main(String[] args)throws ClassNotFoundException{
                Class student = Class.forName("Student");
                
                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);
                }
            }
    
        }
    
  • + 1 comment

    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); 
        }
    }
    

    }

  • + 0 comments

    Keeps happening, arrived to the correct answer in java8 but since it kept saying wrong answer, i had to look for this to find out only java 7 works...

    Please add fixing this to the to do list

  • + 0 comments

    Beware, only Java 7 works for this