{"id":30,"date":"2025-01-10T11:24:18","date_gmt":"2025-01-10T03:24:18","guid":{"rendered":"https:\/\/www.songkl.space\/?p=30"},"modified":"2025-01-10T11:26:57","modified_gmt":"2025-01-10T03:26:57","slug":"java%e4%b8%ad%e7%9a%84functionalinterface","status":"publish","type":"post","link":"https:\/\/www.songkl.space\/?p=30","title":{"rendered":"java\u4e2d\u7684@FunctionalInterface"},"content":{"rendered":"\n<p>\u5728 Java 1.8 \u4e2d\uff0c<code>@FunctionalInterface<\/code>&nbsp;\u662f\u4e00\u4e2a\u6807\u8bb0\u578b\u6ce8\u89e3\uff0c\u7528\u4e8e\u6307\u660e\u4e00\u4e2a\u63a5\u53e3\u662f\u51fd\u6570\u5f0f\u63a5\u53e3\u3002\u51fd\u6570\u5f0f\u63a5\u53e3\u662f\u4ec5\u5305\u542b\u4e00\u4e2a\u62bd\u8c61\u65b9\u6cd5\uff08\u4f46\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u9ed8\u8ba4\u6216\u9759\u6001\u65b9\u6cd5\uff09\u7684\u63a5\u53e3\u3002\u8fd9\u4e2a\u6ce8\u89e3\u4e0d\u662f\u5f3a\u5236\u6027\u7684\uff0c\u4f46\u5982\u679c\u4f60\u5728\u4e00\u4e2a\u63a5\u53e3\u4e0a\u4f7f\u7528\u4e86&nbsp;<code>@FunctionalInterface<\/code>&nbsp;\u6ce8\u89e3\uff0c\u5e76\u4e14\u8be5\u63a5\u53e3\u4e0d\u7b26\u5408\u51fd\u6570\u5f0f\u63a5\u53e3\u7684\u5b9a\u4e49\uff08\u5373\u5305\u542b\u8d85\u8fc7\u4e00\u4e2a\u62bd\u8c61\u65b9\u6cd5\uff09\uff0c\u7f16\u8bd1\u5668\u5c06\u62a5\u9519\u3002<\/p>\n\n\n\n<p>\u51fd\u6570\u5f0f\u63a5\u53e3\u4e3b\u8981\u7528\u4e8e Lambda \u8868\u8fbe\u5f0f\u7684\u7c7b\u578b\u63a8\u65ad\u3002Lambda \u8868\u8fbe\u5f0f\u662f Java 1.8 \u5f15\u5165\u7684\u4e00\u9879\u7279\u6027\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u6d01\u7684\u65b9\u5f0f\u6765\u8868\u793a\u5355\u65b9\u6cd5\u63a5\u53e3\uff08\u4e5f\u79f0\u4e3a\u51fd\u6570\u5f0f\u63a5\u53e3\uff09\u7684\u5b9e\u4f8b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@FunctionalInterface public interface MyFunctionalInterface { void doSomething(); \/\/ \u9ed8\u8ba4\u65b9\u6cd5\uff0c\u4e0d\u5f71\u54cd\u51fd\u6570\u5f0f\u63a5\u53e3\u7684\u5b9a\u4e49 default void doSomethingElse() { System.out.println(\"Doing something else...\"); } \/\/ \u9759\u6001\u65b9\u6cd5\uff0c\u540c\u6837\u4e0d\u5f71\u54cd\u51fd\u6570\u5f0f\u63a5\u53e3\u7684\u5b9a\u4e49 static void staticMethod() { System.out.println(\"This is a static method.\"); } }<\/code><\/pre>\n\n\n\n<p><strong>@FunctionalInterface <\/strong>\u53ef\u4ee5\u5b9e\u73b0\u52a8\u6001\u51fd\u6570<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Java 1.8 \u4e2d\uff0c@FunctionalInterface&nbsp;\u662f\u4e00\u4e2a\u6807\u8bb0\u578b\u6ce8\u89e3\uff0c\u7528\u4e8e\u6307\u660e\u4e00\u4e2a\u63a5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-30","post","type-post","status-publish","format-standard","hentry","category-8"],"_links":{"self":[{"href":"https:\/\/www.songkl.space\/index.php?rest_route=\/wp\/v2\/posts\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.songkl.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.songkl.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.songkl.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.songkl.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=30"}],"version-history":[{"count":3,"href":"https:\/\/www.songkl.space\/index.php?rest_route=\/wp\/v2\/posts\/30\/revisions"}],"predecessor-version":[{"id":34,"href":"https:\/\/www.songkl.space\/index.php?rest_route=\/wp\/v2\/posts\/30\/revisions\/34"}],"wp:attachment":[{"href":"https:\/\/www.songkl.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.songkl.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.songkl.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}