Over a million developers have joined DZone.

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

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

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.

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}