Are defaults in JDK 8 a form of multiple inheritance in Java?

The answer to the duplicate operation is: To solve multiple inheritance issue a class implementing two interfaces providing a default implementation for the same method name and signature must provide an implementation of the method. [Full Article] My answer to your question is: Yes, it is a form of multiple inheritance, because you can inherit … Read more

Weird closure behavior in python

As @thg435 points out, a lambda will not encapsulate the values at that moment, but rather the scope. There are too small ways you can address this: lambda default argument “hack” [ lambda v=i: v for i in [ 1, 2, 3 ] ] Or use functools.partial from functools import partial [ partial(lambda v: v, … Read more

PHP 5.4 – ‘closure $this support’

This was already planned for PHP 5.3, but For PHP 5.3 $this support for Closures was removed because no consensus could be reached how to implement it in a sane fashion. This RFC describes the possible roads that can be taken to implement it in the next PHP version. It indeed means you can refer … Read more

Optional chaining in Swift Closure where return type has to be Void

Optional chaining wraps whatever the result of the right side is inside an optional. So if run() returned T, then x?.run() returns T?. Since run() returns Void (a.k.a. ()), that means the whole optional chaining expression has type Void? (or ()?). When a closure has only one line, the contents of that line is implicitly … Read more

Javascript closures – variable scope question

Its because at the time item.help is evaluated, the loop would have completed in its entirety. Instead, you can do this with a closure: for (var i = 0; i < helpText.length; i++) { document.getElementById(helpText[i].id).onfocus = function(item) { return function() {showHelp(item.help);}; }(helpText[i]); } JavaScript doesn’t have block scope but it does have function-scope. By creating … Read more