An Interface equivalent for reflection

Timothy Schommer timothy2 at iastate.edu
Tue May 7 12:58:05 UTC 2019


I would like to request the addition of an Interface equivalent usable for
reflection. Sometimes when writing a program it is desirable to have the
client program specify how your program should behave in a specific
scenario. Java's reflection can be used to obtain this method, but only if
the client implements it. In this case, a structure for guaranteeing that
the client implements the method is desirable. Interfaces come to mind for
this usage, as the program can type-check the client to ensure that they
implement it. However, what is not always so desirable about using an
Interface for this is the fact that all Interface methods must be public.
You may want to guarantee that the client has access to a method, but you
might not necessarily want every class that uses the client to have access
to the method. Having the client use reflection to pass the method in,
while providing a default implementation yourself is another possibility,
but it is impossible to completely type-check the method passed in until
you try to run it and throw an exception if it doesn't match. For
this reason I would like to request an Interface equivalent designed for
use with Java's reflection.

I understand that, in general, reflection is intended as a bit of a
last-ditch back door access, and that you may not wish to encourage more
general usage of reflection, but I feel that implementing this will make it
so that if people do choose to use reflection for something along the lines
of what I described above, then they can do so while minimizing the
likelihood of of throwing an exception due to an improper of non-existent
method.

Thank you for your time,
Timothy Schommer


More information about the core-libs-dev mailing list