1

Possible Duplicate:
WITH statement in Java

Hi all, does anyone know if there is the With Keyword in Java?

Or something similar..?

Community
  • 1
  • 1
Pacerier
  • 86,231
  • 106
  • 366
  • 634

4 Answers4

5

Luckily, there's no such thing in Java.

Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
2

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);
         }
       });
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

No I don't believe there is such a construct in java, or anything similar, and for good reason :)

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
0
<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

Vikky
  • 752
  • 3
  • 15
  • 35