spring - Java 8 lambda and extension of interfaces with abstract class -



spring - Java 8 lambda and extension of interfaces with abstract class -

say want declare spring's rowmapper, not create dynamic class, implement abstract class implements rowmapper. method signature:

sqlprocedure#declarerowmapper(rowmapper<?> rowmapper);

customrowmapper.java:

public abstract class customrowmapper<t> implements rowmapper<t> { protected a = new a(); }

the old java way write:

sqlproc.declarerowmapper(new customrowmapper<object>() { @override public object maprow(resultset rs, int rownum) { a.dosomething(rs, rownum); homecoming new object(); } });

is possible accomplish same thing lambda expressions? this:

sqlproc.declarerowmapper((rs, rownum) -> { a.dosomething(rs, rownum); homecoming new object(); });

but compile error saying a cannot resolved. it's because java sees implementation of rowmapper#maprow method, not customrowmapper#maprow.

how tell java utilize customrowmapper instead of rowmapper via lambda expressions? possible?

you can extend functional interface , create 1 of own:

@functionalinterface public interface customrowmapper<t> implements rowmapper<t> { static a = new a(); }

then, can pass lambda, implementation of customrowmapper#maprow() method this:

customrowmapper mycustomrowmapperlambda = (rs, rownum) -> { a.dosomething(rs, rownum); homecoming new object(); }; sqlproc.declarerowmapper(mycustomrowmapperlambda);

java spring lambda java-8

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -