jeudi 21 septembre 2017

Retrieve static argument values used within statically declared functional interfaces via java reflection

Take a look at my code here:

import java.util.function.Function;

public class StaticArgumentsTest {

    static Function<String, String> staticConsumer(String testValue) {
        return (st) -> testValue + " and " + st;
    }

    static final Function<String, String> aStaticConsumer =
            staticConsumer("Static String Example Value");

    public static void main(String[] args) {
        System.out.println(StaticArgumentsTest.aStaticConsumer.apply("Dynamic String Example Value"));
    }
}

We've got some legacy code with many of these sorts of functional interface implementations and I would rather have this code in a more manageable state like a database rather than have these settings in plain java code. So my question is, is it possible to find the string value "Static String Example Value" you see above using reflection? I would probably rather do this than just write my own java code parser for this stuff, but as far as I can tell I'm stuck doing that.





Aucun commentaire:

Enregistrer un commentaire