Is there a difference between main(String args[]) and main(String[] args)?

Semantically, they are identical. However, I’d recommend using the latter syntax (String[] args) when declaring arrays. The former syntax is there mainly for compatibility with C syntax. Since String[], as a whole, is the type of the object in Java, it’s more consistent and clear not to split it up. A similar question addresses the … Read more

Check inside method whether some optional argument was passed

Well, arguments are always passed. Default parameter values just ensure that the user doesn’t have to explicitly specify them when calling the function. When the compiler sees a call like this: ExampleMethod(1); It silently converts it to: ExampleMethod(1, “default string”, 10); So it’s not techically possible to determine if the argument was passed at run-time. … Read more

Passing parameters dynamically to variadic functions

Variadic functions use a calling convention where the caller is responsible for popping the function parameters from the stack, so yes, it is possible to do this dynamically. It’s not standardized in C, and normally would require some assembly to manually push the desired parameters, and invoke the variadic function correctly. The cdecl calling convention … Read more

Is there a way to use two ‘…’ statements in a function in R?

An automatic way: foo.plot <- function(x,y,…) { lnames <- names(formals(legend)) pnames <- c(names(formals(plot.default)), names(par())) dots <- list(…) do.call(‘plot’, c(list(x = x, y = x), dots[names(dots) %in% pnames])) do.call(‘legend’, c(“bottomleft”, “bar”, pch = 1, dots[names(dots) %in% lnames])) } pch must be filtered from the lnames to avoid duplication in the legend call in case the user … Read more

Pass in an array of Deferreds to $.when()

To pass an array of values to any function that normally expects them to be separate parameters, use Function.prototype.apply, so in this case you need: $.when.apply($, my_array).then( ___ ); See http://jsfiddle.net/YNGcm/21/ In ES6, you can use the … spread operator instead: $.when(…my_array).then( ___ ); In either case, since it’s unlikely that you’ll known in advance … Read more