defined through the return value of a called method
self-referential, where the new context is equivalent to the last context
terminated through the return of a void context.
1
2
3
4
5
6
<code>author a = author.as(</code><code>"a"</code><code>);</code>
<code>create.selectfrom(a)</code>
<code> </code><code>.where(exists(selectone()</code>
<code> </code><code>.from(book)</code>
<code> </code><code>.where(book.status.eq(book_status.sold_out))</code>
<code> </code><code>.and(book.author_id.eq(a.id))));</code>
<code>string[] datesstr = </code><code>new</code> <code>string[] {</code><code>"12-10-1492"</code><code>, </code><code>"06-12-1978"</code><code>};</code>
<code>...</code>
<code>list<calendar> dates =</code>
<code> </code><code>op.on(datesstr).tolist().map(fnstring.tocalendar(</code><code>"dd-mm-yyyy"</code><code>)).get();</code>
<code>collection mockcollection = easymock.createmock(collection.</code><code>class</code><code>);</code>
<code>easymock.expect(mockcollection.remove(</code><code>null</code><code>)).andthrow(</code><code>new</code> <code>nullpointerexception()).atleastonce();</code>
in the java swing api, the layoutmanager interface defines how container objects can have controlled component placement. one of the more powerful layoutmanager implementations is the gridbaglayout class which requires the use of the gridbagconstraints class to specify how layout control occurs. a typical example of the use of this class is something like the following.
7
8
9
10
11
12
13
14
15
16
17
<code>gridbaglayout gl = </code><code>new</code> <code>gridbaglayout();</code>
<code>jpanel p = </code><code>new</code> <code>jpanel();</code>
<code>p.setlayout( gl );</code>
<code> </code>
<code>jlabel l = </code><code>new</code> <code>jlabel(</code><code>"name:"</code><code>);</code>
<code>jtextfield nm = </code><code>new</code> <code>jtextfield(</code><code>10</code><code>);</code>
<code>gridbagconstraints gc = </code><code>new</code> <code>gridbagconstraints();</code>
<code>gc.gridx = </code><code>0</code><code>;</code>
<code>gc.gridy = </code><code>0</code><code>;</code>
<code>gc.fill = gridbagconstraints.none;</code>
<code>p.add( l, gc );</code>
<code>gc.gridx = </code><code>1</code><code>;</code>
<code>gc.fill = gridbagconstraints.horizontal;</code>
<code>gc.weightx = </code><code>1</code><code>;</code>
<code>p.add( nm, gc );</code>
<code>packer pk = </code><code>new</code> <code>packer( p );</code>
<code>pk.pack( l ).gridx(</code><code>0</code><code>).gridy(</code><code>0</code><code>);</code>
<code>pk.pack( nm ).gridx(</code><code>1</code><code>).gridy(</code><code>0</code><code>).fillx();</code>
there are many places where fluent apis can greatly simplify how software is written and help create an api language that helps users be much more productive and comfortable with the api because the return value of a method always provides a context for further actions in that context.