javareflections

How to use Java Reflections for the "current" application?


The documentation for Reflections gives the first line on how to use Reflections:

Reflections reflections = new Reflections("com.my.project");

Except i don't know the name of the package. This is a piece of library code that should just be able to scan everything in the current package.

What is the Reflections equivalent of the .NET:

//Find all methods in all classes tagged with @Test annotation, 
//and add them to a list.
List<MethodInfo> testMethods = new ArrayList<>();

//Enumerate all assemblies in the current application domain
for (Assembly a : AppDomain.currentDomain.getAssemblies()) {
   //Look at each type (i.e. class) in the assembly
   for (Type t : a.getTypes()) {
      ...
   }
}

in other words, the "current" package? Or in the parlance of .NET

Edit:

Bonus Reading

And the final straw:


Solution

  • Cannot be done.

    Java does not have a reflection system.

    Research Effort