0

Let's say I am making a list of possible items in the game. Every one of them is deriving from the class Item and all of them are placed in the specific package "com.name.app.items".

I want to make a list of them created dynamically, without adding any external information apart from the file containing the class.

I tried getting all files in a package and computing them accordingly but to no avail. Reflection simply refuses to cooperate. No matter what configuration I use, a scanner always returns an empty set.

My second thought was to to simply invoke a static method like ItemDatabase.add(this) but as far as I know it isn't possible without creating an instance of this object or calling a static method from outside.

Is there a go-to method for resolving this kind of issue? Or it is necessary to (apart from declaring the very class) notifying some registry of it's existence?

Neripheral
  • 21
  • 5

1 Answers1

0

After many hours of research I finally found a suitable answer. A simple Gradle task did the job for me as Reflections, ClassGraph etc. doesn't work very well on Android.

Bear in mind that if you would like to read what classes are available in a package on runtime - it will be a very difficult task so find another solution or prepare yourself for a long journey.

Neripheral
  • 21
  • 5