I'm trying to create a method that puts a Function's results in to a Consumer you using unbound references (I think). Here's the scenario. With JDBC's ResultSet you can get row values by index. I have a Bean instance I want to place selected values into. I'm looking for a way to avoid writing boiler plate mapping code but instead achieve something like:
static <T> void copy(Consumer<T> setter, Function<T, Integer> getter, Integer i);
And call it like:
copy(Bean::setAValue, ResultSet::getString, 0)
I don't want the bind Bean
and ResultSet
to instance too early since I want this to be usable with any bean of ResultSet
.
The example I've been trying to work from is:
public static <T> void println(Function<T,String> function, T value) {
System.out.println(function.apply(value));
}
Called via:
println(Object::toString, 0L);