dimanche 3 avril 2016

Scala - scan package/folder for implementations of a Trait

If wonder if it's possible to "scan" for classes that implement a certain trait and are located in a pred-defined package and/or folder. My application provides a trait that can be implemented, it would be nice to programmatically get a list of all implementations at runtime without having to "manually register" every implementation first.

I found a similar question and the accepted answer proposes the usage of ServiceLoader. However, it's still necessary to list the available implementations in a text file (META-INF/services).

I understand that it probably would be too expensive to scan all classes for the specific type. But I thought that perhaps restricting the search to a certain package or folder could help?





Aucun commentaire:

Enregistrer un commentaire