java equivalent of ruby's ||= syntax
Posted
by brad
on Stack Overflow
See other posts from Stack Overflow
or by brad
Published on 2010-03-29T17:55:08Z
Indexed on
2010/03/29
18:03 UTC
Read the original article
Hit count: 353
I'm brand new to java, coming from a ruby world. One thing I love about ruby is the very terse syntax such as ||=.
I realize of course that a compiled language is different, but I'm wondering if Java has anything similar.
In particular, what I do all the time in ruby is something like:
someVar ||= SomeClass.new
I think this is incredibly terse, yet powerful, but thus far the only method I can think of to achieve the same thing is a very verbose:
if(someVar == null){
someVar = new SomeClass()
}
Just trying to improve my Java-fu and syntax is certainly one area that I'm no pro.
© Stack Overflow or respective owner