{"id":1427,"date":"2022-11-03T23:01:29","date_gmt":"2022-11-03T15:01:29","guid":{"rendered":"https:\/\/qaqaq.top\/?p=1427"},"modified":"2022-11-27T12:39:44","modified_gmt":"2022-11-27T04:39:44","slug":"lambda%e8%a1%a8%e8%be%be%e5%bc%8f%e4%bd%bf%e7%94%a8%e4%b8%be%e4%be%8b","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=1427","title":{"rendered":"Lambda\u8868\u8fbe\u5f0f\u4f7f\u7528\u4e3e\u4f8b"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P668;\r\n\r\nimport org.junit.jupiter.api.Test;\r\n\r\nimport java.util.Comparator;\r\n\r\n\/**\r\n * Lambda\u8868\u8fbe\u5f0f\u7684\u4f7f\u7528\u4e3e\u4f8b\r\n *\r\n * @author RichieZhang\r\n * @create 2022-11-03 \u4e0b\u5348 3:08\r\n *\/\r\npublic class LambdaTest {\r\n\r\n    @Test\r\n    public void test1(){\r\n        Runnable r1 = new Runnable() {\r\n            @Override\r\n            public void run() {\r\n                System.out.println(\"\u6211\u7231\u5317\u4eac\u5929\u5b89\u95e8\");\r\n            }\r\n        };\r\n\r\n        r1.run();\r\n\r\n        System.out.println(\"***************************\");\r\n\r\n        Runnable r2 = () -> System.out.println(\"\u6211\u7231\u5317\u4eac\u6545\u5bab\");\r\n\r\n        r2.run();\r\n    }\r\n\r\n    @Test\r\n    public void test2(){\r\n        Comparator&lt;Integer> com1 = new Comparator&lt;Integer>() {\r\n            @Override\r\n            public int compare(Integer o1, Integer o2) {\r\n                return Integer.compare(o1,o2);\r\n            }\r\n        };\r\n\r\n        int compare1 = com1.compare(12, 21);\r\n        System.out.println(compare1);\r\n\r\n        System.out.println(\"***************************\");\r\n\r\n        \/\/Lambda\u8868\u8fbe\u5f0f\u7684\u5199\u6cd5\r\n        Comparator&lt;Integer> com2 = ((o1, o2) -> Integer.compare(o1,o2));\r\n\r\n        int compare2 = com2.compare(32, 21);\r\n        System.out.println(compare2);\r\n\r\n        System.out.println(\"***************************\");\r\n\r\n        \/\/\u65b9\u6cd5\u5f15\u7528\r\n        Comparator&lt;Integer> com3 = Integer::compare;\r\n\r\n        int compare3 = com3.compare(32, 21);\r\n        System.out.println(compare3);\r\n\r\n    }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-1427","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1427"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1427"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1427\/revisions"}],"predecessor-version":[{"id":1428,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1427\/revisions\/1428"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}