Find all classes in package (& call static methods) at runtime
问题 I have a package in which there are many classes, and these classes all have a static method called onLoad . I want to call the onLoad method when the program starts, however I do not want to hard-wire each and every one, i.e. classA.onLoad(); classB.onLoad(); etc. How can I list all classes in package com.foo.bar.asd and run onLoad() on all of them? Thanks in advance 回答1: I found this question quite interesting so I came up with a solution. The tricky part here is to actually find all