0

I have a base interface FunctionCredential:

public interface FunctionPrivilege {}

and several other interfaces extending this interface:

public interface ReadSomethingPrivilege extends FunctionPrivilege {}
public interface WriteSomethingPrivilege extends FunctionPrivilege {}
...

The interfaces are used as marker interfaces only (no implementations). I want to discover interfaces (all reachable using the current context classloader), not check known interfaces.

Within a Java application, can I somehow discover (list) those interface classes at runtime? If so, how would I do that?

Note: CDI does something similar, also discovering/scanning classes at runtime.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Peter Walser
  • 15,208
  • 4
  • 51
  • 78
  • I think you can do something with reflection – Bruno Nov 25 '16 at 10:45
  • You want to get `ReadSomethingPrivilege` and `WriteSomethingPrivilege` from `FunctionPrivilege` ? – Nicolas Filotto Nov 25 '16 at 10:54
  • What are you expecting, to list all interfaces that extends `FunctionPrivilege` ? Or to know if an Interface extend it. If you want to list this, [this link](http://stackoverflow.com/a/520339/4391450) could interest you – AxelH Nov 25 '16 at 10:57
  • If I could just list all classes, I'd be happy, as I can check the classes myself using reflection (check if interface and if it extends the base interface). – Peter Walser Nov 25 '16 at 11:35
  • 1
    Probably you can use Guava's [ClassPath](http://google.github.io/guava/releases/snapshot/api/docs/com/google/common/reflect/ClassPath.html). – PeterMmm Nov 25 '16 at 12:46
  • 1
    Classindex may help: https://github.com/atteo/classindex – maress Nov 25 '16 at 13:37
  • _"I want to discover interfaces (all reachable using the current context classloader)"_ - beats me what that means. – ivan_pozdeev Nov 26 '16 at 17:41

0 Answers0