how java compiler solved lambda return type while Predicate's method can only return boolean?












-2














Note: this question look like some others but different



Things i can't understand is that we know java doesn't support dynamic type even use Lambda, and it's compiled to Predictor during compile time.



Things i can't understand is that Predicator's default method only can return boolean, while Lambda expression can return anything. HOW is this archived?










share|improve this question
























  • What is a Predicator? And Lambdas are compiled to implement a functional interface.
    – Henry
    Nov 20 at 10:03






  • 1




    "this question look like some others but different". Whenever you say anything like this in a question, you should explain what you have already found and how its different from what you're asking.
    – Michael
    Nov 20 at 10:04










  • He probably means java.util.function.Predicate. Anyway, I believe that this question is a bit too broad for stackoverflow, because the answer would be an explanation of how lambdas work in java.
    – Dvorog
    Nov 20 at 10:24












  • i mean "java.util.function.Predicate"
    – Ben Xu
    Nov 21 at 6:31
















-2














Note: this question look like some others but different



Things i can't understand is that we know java doesn't support dynamic type even use Lambda, and it's compiled to Predictor during compile time.



Things i can't understand is that Predicator's default method only can return boolean, while Lambda expression can return anything. HOW is this archived?










share|improve this question
























  • What is a Predicator? And Lambdas are compiled to implement a functional interface.
    – Henry
    Nov 20 at 10:03






  • 1




    "this question look like some others but different". Whenever you say anything like this in a question, you should explain what you have already found and how its different from what you're asking.
    – Michael
    Nov 20 at 10:04










  • He probably means java.util.function.Predicate. Anyway, I believe that this question is a bit too broad for stackoverflow, because the answer would be an explanation of how lambdas work in java.
    – Dvorog
    Nov 20 at 10:24












  • i mean "java.util.function.Predicate"
    – Ben Xu
    Nov 21 at 6:31














-2












-2








-2







Note: this question look like some others but different



Things i can't understand is that we know java doesn't support dynamic type even use Lambda, and it's compiled to Predictor during compile time.



Things i can't understand is that Predicator's default method only can return boolean, while Lambda expression can return anything. HOW is this archived?










share|improve this question















Note: this question look like some others but different



Things i can't understand is that we know java doesn't support dynamic type even use Lambda, and it's compiled to Predictor during compile time.



Things i can't understand is that Predicator's default method only can return boolean, while Lambda expression can return anything. HOW is this archived?







java lambda






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 12:59









Federico Peralta Schaffner

21.8k43369




21.8k43369










asked Nov 20 at 10:00









Ben Xu

6552720




6552720












  • What is a Predicator? And Lambdas are compiled to implement a functional interface.
    – Henry
    Nov 20 at 10:03






  • 1




    "this question look like some others but different". Whenever you say anything like this in a question, you should explain what you have already found and how its different from what you're asking.
    – Michael
    Nov 20 at 10:04










  • He probably means java.util.function.Predicate. Anyway, I believe that this question is a bit too broad for stackoverflow, because the answer would be an explanation of how lambdas work in java.
    – Dvorog
    Nov 20 at 10:24












  • i mean "java.util.function.Predicate"
    – Ben Xu
    Nov 21 at 6:31


















  • What is a Predicator? And Lambdas are compiled to implement a functional interface.
    – Henry
    Nov 20 at 10:03






  • 1




    "this question look like some others but different". Whenever you say anything like this in a question, you should explain what you have already found and how its different from what you're asking.
    – Michael
    Nov 20 at 10:04










  • He probably means java.util.function.Predicate. Anyway, I believe that this question is a bit too broad for stackoverflow, because the answer would be an explanation of how lambdas work in java.
    – Dvorog
    Nov 20 at 10:24












  • i mean "java.util.function.Predicate"
    – Ben Xu
    Nov 21 at 6:31
















What is a Predicator? And Lambdas are compiled to implement a functional interface.
– Henry
Nov 20 at 10:03




What is a Predicator? And Lambdas are compiled to implement a functional interface.
– Henry
Nov 20 at 10:03




1




1




"this question look like some others but different". Whenever you say anything like this in a question, you should explain what you have already found and how its different from what you're asking.
– Michael
Nov 20 at 10:04




"this question look like some others but different". Whenever you say anything like this in a question, you should explain what you have already found and how its different from what you're asking.
– Michael
Nov 20 at 10:04












He probably means java.util.function.Predicate. Anyway, I believe that this question is a bit too broad for stackoverflow, because the answer would be an explanation of how lambdas work in java.
– Dvorog
Nov 20 at 10:24






He probably means java.util.function.Predicate. Anyway, I believe that this question is a bit too broad for stackoverflow, because the answer would be an explanation of how lambdas work in java.
– Dvorog
Nov 20 at 10:24














i mean "java.util.function.Predicate"
– Ben Xu
Nov 21 at 6:31




i mean "java.util.function.Predicate"
– Ben Xu
Nov 21 at 6:31












1 Answer
1






active

oldest

votes


















1














while Lambda expression can return anything. This is wrong



A lambda expression is written to a corresponding abstract method in a function interface



Considering Predicate as an example, lambda expression will be written to corresponding abstract method which is boolean test(T t)



From java docs here with an clear example




A functional interface is any interface that contains only one abstract method. (A functional interface may contain one or more default methods or static methods.) Because a functional interface contains only one abstract method, you can omit the name of that method when you implement it. To do this, instead of using an anonymous class expression, you use a lambda expression, which is highlighted in the following method invocation:




Refer : Approach 5: Specify Search Criteria Code with a Lambda Expression



Refer : Approach 6: Use Standard Functional Interfaces with Lambda Expressions






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390451%2fhow-java-compiler-solved-lambda-return-type-while-predicates-method-can-only-re%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    while Lambda expression can return anything. This is wrong



    A lambda expression is written to a corresponding abstract method in a function interface



    Considering Predicate as an example, lambda expression will be written to corresponding abstract method which is boolean test(T t)



    From java docs here with an clear example




    A functional interface is any interface that contains only one abstract method. (A functional interface may contain one or more default methods or static methods.) Because a functional interface contains only one abstract method, you can omit the name of that method when you implement it. To do this, instead of using an anonymous class expression, you use a lambda expression, which is highlighted in the following method invocation:




    Refer : Approach 5: Specify Search Criteria Code with a Lambda Expression



    Refer : Approach 6: Use Standard Functional Interfaces with Lambda Expressions






    share|improve this answer




























      1














      while Lambda expression can return anything. This is wrong



      A lambda expression is written to a corresponding abstract method in a function interface



      Considering Predicate as an example, lambda expression will be written to corresponding abstract method which is boolean test(T t)



      From java docs here with an clear example




      A functional interface is any interface that contains only one abstract method. (A functional interface may contain one or more default methods or static methods.) Because a functional interface contains only one abstract method, you can omit the name of that method when you implement it. To do this, instead of using an anonymous class expression, you use a lambda expression, which is highlighted in the following method invocation:




      Refer : Approach 5: Specify Search Criteria Code with a Lambda Expression



      Refer : Approach 6: Use Standard Functional Interfaces with Lambda Expressions






      share|improve this answer


























        1












        1








        1






        while Lambda expression can return anything. This is wrong



        A lambda expression is written to a corresponding abstract method in a function interface



        Considering Predicate as an example, lambda expression will be written to corresponding abstract method which is boolean test(T t)



        From java docs here with an clear example




        A functional interface is any interface that contains only one abstract method. (A functional interface may contain one or more default methods or static methods.) Because a functional interface contains only one abstract method, you can omit the name of that method when you implement it. To do this, instead of using an anonymous class expression, you use a lambda expression, which is highlighted in the following method invocation:




        Refer : Approach 5: Specify Search Criteria Code with a Lambda Expression



        Refer : Approach 6: Use Standard Functional Interfaces with Lambda Expressions






        share|improve this answer














        while Lambda expression can return anything. This is wrong



        A lambda expression is written to a corresponding abstract method in a function interface



        Considering Predicate as an example, lambda expression will be written to corresponding abstract method which is boolean test(T t)



        From java docs here with an clear example




        A functional interface is any interface that contains only one abstract method. (A functional interface may contain one or more default methods or static methods.) Because a functional interface contains only one abstract method, you can omit the name of that method when you implement it. To do this, instead of using an anonymous class expression, you use a lambda expression, which is highlighted in the following method invocation:




        Refer : Approach 5: Specify Search Criteria Code with a Lambda Expression



        Refer : Approach 6: Use Standard Functional Interfaces with Lambda Expressions







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 at 10:11

























        answered Nov 20 at 10:05









        Deadpool

        3,5692324




        3,5692324






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390451%2fhow-java-compiler-solved-lambda-return-type-while-predicates-method-can-only-re%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Create new schema in PostgreSQL using DBeaver

            Deepest pit of an array with Javascript: test on Codility

            Fotorealismo