polygene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niclas Hedhman <nic...@hedhman.org>
Subject Java 8 and Zest
Date Wed, 03 Jun 2015 09:51:49 GMT
I just wanted to share one really cool thing that came out of using Java 8
with Zest. A bit advanced course, but I think it can come to make Qi4j 3.0
really awesome...

I have been using ValueBuilderFactory.newValueBuilderWithState() quite a
lot, and it used to be really nasty, due to the immense 'noise' that each
function became ananonymous class with all the boilerplate. Instead, we end
up with something like this;

ValueBuilder<T> builder = module.newValueBuilderWithState(
    descriptor -> {
        String name = descriptor.qualifiedName().name();
        return attributes.get( name );
    descriptor -> null,
    descriptor -> null,
    descriptor -> null

So, even though Qi4j isn't using the Java 8 functions, the compiler has
enough sugar-coating handling of anonymous classes with single methods.

It is also possible, to do MethodReferences in neat ways. Look at this;

    .filter( specification::satisfiedBy )
    .map( entity -> uow.toValue( entityType, (T) entity ) )
    .forEach( result::add );

That filter() nicely accepts Qi4j Specification instances (yeah, the above
is to expand ManyAssocation references to ValueComposites, subject to a

I can't wait to get going on Qi4j ver 3.0, but it is nice to know that
there are benefits even with the current codebase.

Niclas Hedhman, Software Developer
http://zest.apache.org - New Energy for Java

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message