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
  • 81,402
  • 98
  • 349
  • 618

4 Answers4

5

Luckily, there's no such thing in Java.

Anton Gogolev
  • 110,157
  • 37
  • 194
  • 282
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
  • 513,304
  • 74
  • 731
  • 1,106
0

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

Sam Holder
  • 31,788
  • 13
  • 99
  • 173
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
  • 712
  • 3
  • 15
  • 33