Var-arrrrrgh!
-
Two posts today. Just found a geniurrrs way of using varargs.
public static void doThing(String...args) { if (args != null && args.length > 0) doMore(args[0]); if (args != null && args.length > 1) doMore(args[1]); }
-
It probably used to look like:
public static void doThing(String...args) { for( int i = 0; i < args.length; ++i ){ doMore( args[i] ); if( i = 1 ) break; } }
And then someone decided to optimize this by unrolling the loop.
-
if( i = 1 )
Nice touch.
-
-
@Mo6eB said:
@lolwhat said:
if( i = 1 )
Nice touch.
This would be a syntax error in Java unfortunately.
See, that's why they unrolled it. It wouldn't compile.
-
@mozbo said:
@Mo6eB said:
@lolwhat said:
if( i = 1 )
Nice touch.
This would be a syntax error in Java unfortunately.
See, that's why they unrolled it. It wouldn't compile.
That must be exactly why they used the > operator instead because == vs = was just too confusing.
-
Nice. They probably are working in a large messy enterprise code base, and were afraid to change the method signature for fear of breaking something else.
-
what, seriously... it's the original darkmatter?
screw him for taking my name and then posting so little!edit: interesting how i joined in 2008 and darkmatter wasn't available until he joined in 2012.
screw community server too.
-
@darkmattar said:
what, seriously... it's the original darkmatter?
screw him for taking my name and then posting so little!edit: interesting how i joined in 2008 and darkmatter wasn't available until he joined in 2012.
screw community server too.
I was surprised it was available, usually I have to throw an extra 'r' on the end!