1

Within the same project I am trying to get all the files that contain enum. I don't know the file names that contain this.

I normally could do: .getClass().getResourceAsStream("file.txt");

but in this case I'm not sure how to do this.

J_Strauton
  • 2,270
  • 3
  • 28
  • 70
  • Are you trying to do this at runtime, on the phone? If so, your Kotlin source code usually is not packaged in the APK. – CommonsWare Oct 31 '21 at 18:59

1 Answers1

2

Here is the way you can get the classes inside your application. Can you find all classes in a package using reflection?

It requires this library https://github.com/ronmamo/reflections

Once you get all classes you can iterate through all of them and use this solution. Checking if a class is java.lang.Enum

There are a few caveats when trying to figure out if a class is truly an enum depending on where it exists. The accepted answer has 3 solutions to deal with the caveats.

Note this is in Java but should be easily convertible.

avalerio
  • 2,072
  • 1
  • 12
  • 11