We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The code loops through all of the methods in the FamilyMember class (seniorMember(...) and juniorUser(...)) for each test. For each method, it gets the annotations and checks to see if it's a valid method to call for the current role; if it is, it calls it with the method.invoke(...) line.
In other words, this is very obviously tutorial code, not something you would (I hope!) write in the real world. It's not going to be very performant; it would perform weirdly if there were multiple methods for the same role; and if the methods have different footprints, it throws an "IllegalArgumentException" at run (not compile) time.
This test shows you how annotations can be used, but not how they should be.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Annotations
You are viewing a single comment's thread. Return to all comments →
The code loops through all of the methods in the FamilyMember class (seniorMember(...) and juniorUser(...)) for each test. For each method, it gets the annotations and checks to see if it's a valid method to call for the current role; if it is, it calls it with the method.invoke(...) line.
In other words, this is very obviously tutorial code, not something you would (I hope!) write in the real world. It's not going to be very performant; it would perform weirdly if there were multiple methods for the same role; and if the methods have different footprints, it throws an "IllegalArgumentException" at run (not compile) time.
This test shows you how annotations can be used, but not how they should be.