Java Reflection - Attributes

Sort by

recency

|

121 Discussions

|

  • + 0 comments

    Just to mention to either run the code using Java 7 or add the following methods for the Student Class, as they are also required for the output assertion:

    		public void dnqvo(){  }
    		public void bwkbd(){  }
    		public void rmjig(){  }
    		public void amftc(){  }
    		public void kgwku(){  }
    		public void ogvdl(){  }
    		public void viyog(){  }
    		public void pqfct(){  }
    		public void iwhtf(){  }
    		public void ptrup(){  }
    		public void viwuu(){  }
    		public void tkbpp(){  }
    		public void plaob(){  }
    		public void ghtlj(){  }
    		public void pvgyp(){  }
    		public void ormim(){  }
    		public void cfwyc(){  }
    		public void sumvl(){  }
    		public void elyed(){  }
    		public void cmkxa(){  }
    		public void toxdp(){  }
    		public void qthde(){  }
    		public void whjtj(){  }
    		public void moebl(){  }
    		public void piwro(){  }
    		public void atcks(){  }
    		public void ehjdm(){  }
    		public void ytijy(){  }
    		public void migyc(){  }
    		public void pnruo(){  }
    		public void fmyce(){  }
    		public void odyqp(){  }
    		public void twyfa(){  }
    		public void levtp(){  }
    		public void ujxei(){  }
    		public void dvvwq(){  }
    		public void mcgme(){  }
    		public void kbjlt(){  }
    		public void ahqym(){  }
    		public void tntpj(){  }
    		public void jnskt(){  }
    		public void dnpym(){  }
    		public void jmopy(){  }
    		public void uccfq(){  }
    		public void vhxoi(){  }
    		public void nixhb(){  }
    		public void isqdf(){  }
    		public void khuag(){  }
    		public void hluvb(){  }
    
  • + 0 comments

    Bumping to top.. to say this only works in Java 7.

  • + 0 comments
    class Solution {
    
        public static void main(String[] args){
            Class student = new Student().getClass();
            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
    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);
                }
            }
    
        }
    
  • + 0 comments

    here is Java Reflection - Attributes solution - https://programmingoneonone.com/hackerrank-java-reflection-attributes-problem-solution.html