{"id":91,"date":"2020-02-23T23:16:16","date_gmt":"2020-02-23T15:16:16","guid":{"rendered":"https:\/\/liushiming.cn\/?p=91"},"modified":"2020-03-27T18:55:57","modified_gmt":"2020-03-27T10:55:57","slug":"java-static-methods","status":"publish","type":"post","link":"https:\/\/liushiming.cn\/article\/java-static-methods.html","title":{"rendered":"java\u63a5\u53e3\u9759\u6001\u65b9\u6cd5"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f932ab21847\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69f932ab21847\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/liushiming.cn\/article\/java-static-methods.html\/#%E6%A6%82%E8%BF%B0\" >\u6982\u8ff0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/liushiming.cn\/article\/java-static-methods.html\/#%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95\" >\u9759\u6001\u65b9\u6cd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/liushiming.cn\/article\/java-static-methods.html\/#%E4%B8%BA%E4%BB%80%E4%B9%88%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%94%AF%E6%8C%81%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95\" >\u4e3a\u4ec0\u4e48\u63a5\u53e3\u8981\u652f\u6301\u9759\u6001\u65b9\u6cd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/liushiming.cn\/article\/java-static-methods.html\/#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99\" >\u53c2\u8003\u8d44\u6599<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%E6%A6%82%E8%BF%B0\"><\/span>\u6982\u8ff0<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Java8\u5e26\u6765\u4e86\u4e00\u4e9b\u5168\u65b0\u7684\u7279\u6027\uff0c\u5305\u62eclambda\u8868\u8fbe\u5f0f\u3001\u51fd\u6570\u63a5\u53e3\u3001\u65b9\u6cd5\u5f15\u7528\u3001\u6d41\u3001\u53ef\u9009\u65b9\u6cd5\u3001\u63a5\u53e3\u4e2d\u7684\u9759\u6001\u65b9\u6cd5\u548c<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/liushiming.cn\/2020\/02\/23\/java-default-methods\/\">\u9ed8\u8ba4\u65b9\u6cd5<\/a>\u3002<\/p>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u8ba8\u8bba\u4e3a\u4ec0\u4e48java8\u63a5\u53e3\u65b0\u589e\u4e86\u9ed8\u8ba4\u65b9\u6cd5\uff0c\u5982\u4f55\u4f7f\u7528\u9ed8\u8ba4\u65b9\u6cd5\uff0c\u5e76\u8ba8\u8bba\u4e00\u4e9b\u6709\u7528\u7684\u7528\u4f8b\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95\"><\/span>\u9759\u6001\u65b9\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u63a5\u53e3\u4e2d\u7684\u9759\u6001\u65b9\u6cd5\u548c\u7c7b\u4e2d\u5b9a\u4e49\u7684\u9759\u6001\u65b9\u6cd5\u4e00\u6837\uff0c\u4e0d\u5c5e\u4e8e\u7279\u5b9a\u5bf9\u8c61\uff0c\u6240\u4ee5\u5b83\u4eec\u4e0d\u662f\u5b9e\u73b0\u63a5\u53e3\u7684api\u7684\u4e00\u90e8\u5206\uff0c\u5fc5\u987b\u4f7f\u7528InterfaceName.staticMethod\u6765\u8c03\u7528\u5b83\u4eec\u3002<\/p>\n<p>\u4e3a\u4e86\u7406\u89e3\u9759\u6001\u65b9\u6cd5\u5982\u4f55\u5728\u63a5\u53e3\u4e2d\u5de5\u4f5c\uff0c\u8ba9\u6211\u4eec\u770b\u4e00\u4e2a\u5b9e\u4f8b:<\/p>\n<pre><code class=\"language-java \">interface NewInterface { \n\n    \/\/ \u9759\u6001\u65b9\u6cd5\n    static void hello() \n    { \n        System.out.println(\"Hello, New Static Method Here\"); \n    } \n\n    \/\/ \u62bd\u8c61\u65b9\u6cd5 \n    void overrideMethod(String str); \n} \n\n\/\/ \u5b9e\u73b0\u7c7b\npublic class InterfaceDemo implements NewInterface { \n\n    public static void main(String[] args) \n    { \n        InterfaceDemo interfaceDemo = new InterfaceDemo(); \n\n        \/\/ \u8c03\u7528\u63a5\u53e3\u9759\u6001\u65b9\u6cd5 \n        NewInterface.hello(); \n\n        \/\/ \u8c03\u7528\u88ab\u8986\u5199\u540e\u62bd\u8c61\u65b9\u6cd5 \n        interfaceDemo.overrideMethod(\"Hello, Override Method here\"); \n    } \n\n    \/\/ \u5b9e\u73b0\u63a5\u53e3\u65b9\u6cd5\n    @Override\n    public void overrideMethod(String str) \n    { \n        System.out.println(str); \n\n<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"%E4%B8%BA%E4%BB%80%E4%B9%88%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%94%AF%E6%8C%81%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95\"><\/span>\u4e3a\u4ec0\u4e48\u63a5\u53e3\u8981\u652f\u6301\u9759\u6001\u65b9\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u63a5\u53e3\u4e2d\u7684\u9759\u6001\u65b9\u6cd5\u80cc\u540e\u7684\u601d\u60f3\u662f\u63d0\u4f9b\u4e00\u79cd\u7b80\u5355\u7684\u673a\u5236\uff0c<strong>\u5141\u8bb8\u901a\u8fc7\u5c06\u76f8\u5173\u7684\u65b9\u6cd5\u5185\u805a\u5728\u63a5\u53e3\u4e2d\uff0c\u800c\u4e0d\u5fc5\u521b\u5efa\u65b0\u7684\u5bf9\u8c61<\/strong>\u3002<\/p>\n<p><strong>\u62bd\u8c61\u7c7b\u4e5f\u53ef\u4ee5\u505a\u540c\u6837\u7684\u4e8b\u60c5<\/strong>\u3002\u4e3b\u8981\u7684\u533a\u522b\u5728\u4e8e<strong>\u62bd\u8c61\u7c7b\u53ef\u4ee5\u6709\u6784\u9020\u51fd\u6570\u3001\u6210\u5458\u53d8\u91cf\u548c\u65b9\u6cd5\u3002<\/strong><\/p>\n<p>\u63a8\u8350\u628a\u548c\u53ea\u548c\u63a5\u53e3\u76f8\u5173\u7684\u9759\u6001utility\u65b9\u6cd5\u653e\u5728\u63a5\u53e3\u4e2d\uff08\u63d0\u9ad8\u5185\u805a\u6027\uff09\uff0c\u800c\u4e0d\u9700\u8981\u989d\u5916\u521b\u5efa\u4e00\u4e9butility\u7c7b\u4e13\u95e8\u53bb\u653e\u7f6e\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99\"><\/span>\u53c2\u8003\u8d44\u6599<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Baeldung &#8211; <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.baeldung.com\/java-static-default-methods\">Static and Default Methods in Interfaces in Java<\/a><br \/>\ngeeksforgeeks &#8211; <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.geeksforgeeks.org\/static-method-in-interface-in-java\/\">Static method in Interface in Java<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u6587\u641e\u61c2java\u63a5\u53e3\u9759\u6001\u65b9\u6cd5<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"no","_lmt_disable":"","footnotes":""},"categories":[4,29],"tags":[49,50],"class_list":["post-91","post","type-post","status-publish","format-standard","hentry","category-java","category-tutorial","tag-java","tag-tutorial"],"modified_by":"Shiming","_links":{"self":[{"href":"https:\/\/liushiming.cn\/wp-json\/wp\/v2\/posts\/91","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liushiming.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liushiming.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liushiming.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/liushiming.cn\/wp-json\/wp\/v2\/comments?post=91"}],"version-history":[{"count":3,"href":"https:\/\/liushiming.cn\/wp-json\/wp\/v2\/posts\/91\/revisions"}],"predecessor-version":[{"id":308,"href":"https:\/\/liushiming.cn\/wp-json\/wp\/v2\/posts\/91\/revisions\/308"}],"wp:attachment":[{"href":"https:\/\/liushiming.cn\/wp-json\/wp\/v2\/media?parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liushiming.cn\/wp-json\/wp\/v2\/categories?post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/liushiming.cn\/wp-json\/wp\/v2\/tags?post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}