Is there a simple, well-studied way to search for a given class by name in a package and, recursively, in all subpackages of this package?
those. taking into account existing classes, for example:
foo.MyClassfoo.bar.baz.some.more.MyClassfoo.bar.baz.some.more.OtherClass
I would like to run something like magicMethod("foo.bar.baz", "MyClass")and get Class foo.bar.baz.some.more.MyClassas a result.
Obviously, it’s quite easy to implement it manually - by examining the downloaded packages from Package.getPackages(), filtering whatever is suitable and searching for the class in a loop using Class.forName(...)- but there might be something in the standard Java libraries or some other widespread library such as Apache Commons who solve this problem?
source
share