So, if you have even a tiny bit of Java experience you know about the normal format of the if/then/else control flow.
if(something that might be true){
do this;
}else{
do that;
}
or alternatively,
if(something that might be true){
do this;
}else if(something else that might be true){
do that;
}else{
do the alternative.
}
Of course there are a number of ways to make these statements shorter, like ommitting closing curly braces if the 'do this' operation is one line, etc.
These shorter ways are a little harder to read, but make the code a little more compact which can be a good thing.
But there is an even SHORTER way! If you just have a simple if/then/else statement, nothing fancy, just one operation for the if and the else, then you can get it down to one line.
To make this even more cryptic, it is not even necessary to use the words 'if' or 'else' in there at all: in place of if is '?' and in place of else is ':'.
So the above code fragment would look like this:
(something that might be true)?do this:do that;
This is getting suspiciously like Perl, if you ask me. Java heresy! ;)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment