The following code is extracted from a Scala project that parses a stream of marshalled binary
messages. The code that actually unmarshals the bytes is defined by
The Scala code implements a test harness for a Java system. That Java (only) codebase also has to unmarshal the byte stream and would thus be convenient to make the Unmarshaller code common between the two codebases.
The Java 8 lambdas provide an equivalent representation.
Note that is the only change required in the Scala code. The scala compiler desugars
unmarshal.apply(x,y), which corresponds to the
Unfortunately, the Java API does not consistently use
apply, so this syntactic convenience
is limited. For example
(Int)=>Unit corresponds to
Consumer<Unit>, whose API