Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Fluent interfaces are finally ready for prime time in Java

DZone's Guide to

Fluent interfaces are finally ready for prime time in Java

· Java Zone ·
Free Resource

How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.

One of the basic needs in fluent interface is connecting to user types. What field, method or operation does this fluent interface try to refer? This is not an easy question for the interface implementer! There are many techniques available to get this information, from mocking user types to providing a DSL for supported operations. But they have costs, require learning or plumbing code or are not refactoring friendly.

In C# this problem is solved by 2 language features: Lambda expressions and Expression Trees. For example, consider this:

var results = someCollection.where(c => c.SomeProperty < someValue * 2);

in C# library developer can get an expression tree of the user predicate above, and convert it to the proper behavior.

Java 8 provides the first feature and the second... is provided by JaQue project:

void method(Predicate<Customer> p) {
  LambdaExpression<Predicate<Customer>> parsed = LambdaExpression.parse(p);
  //Use parsed Expression Tree...
}

There is a hot discussion about an impact of Lambda expressions on JavaEE development. With JaQue Java becomes a semantic language, giving the libraries developers an ability to specify the meaning of user code at runtime.

How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}