java – Functional interface implementation

Question:

Understanding of the interface as a language construct, until some time I seemed to have acquired it. When confronted with lambda expressions, this understanding runs the risk of being revised. What I mean?

The interface allows you to "combine" in some sense relatively different classes and work with them from a certain angle (interface). One way or another, in order to use it (the interface), it must be implemented.

Do functional interfaces that define one method behave differently? You don't need to implement them, just create a link to them and assign a lambda expression to those links?

I am interested in the very scale of the possibilities that opens up here. Is it just a reference to a functional interface inside any class that can manipulate objects of any class?

Answer:

Just as an example, what exactly is a lambda in Java

Lambda

new AccidentsRequest(result -> {if (!result.has("error")) parseJSON(result);}, true);

FUCK-TIBIDOH, AHALAY-MAHALAY !!! And the lambda turns … Into an anonymous class!

new AccidentsRequest(new AsyncTaskCompleteListener() {
        @Override
        public void onTaskComplete(JSONObject result) throws JSONException {
            if (!result.has("error")) Content.this.parseJSON(result);
        }
    }, true);

In fact, lambdas in Java are such syntactic sugar for anonymous classes with one method.

Scroll to Top