Possible Duplicate:
WITH statement in Java
Hi all, does anyone know if there is the With Keyword
in开发者_开发百科 Java?
Or something similar..?
Luckily, there's no such thing in Java.
There is something similar with chained calls.
e.g.
StringBuilder sb = new StringBuilder();
sb.append("Hello")
.append("World")
.reverse();
This is a common pattern with builder objects. However, it is not Java language feature.
From the Guava MapMake example
ConcurrentMap<Key, Graph> graphs = new MapMaker()
.concurrencyLevel(4)
.weakKeys()
.maximumSize(10000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.makeComputingMap(
new Function<Key, Graph>() {
public Graph apply(Key key) {
return createExpensiveGraph(key);
}
});
No I don't believe there is such a construct in java, or anything similar, and for good reason :)
<script type="text/javascript">
function FunctionProxy( sourceCode ){
return(
Function(
"with (this){" +
"return(" +
"(function(){" + sourceCode + "})()" +
");" +
"};"
)
)};
with keywrd is used in c# and javascript, not in java
精彩评论