{"id":36425,"date":"2024-11-26T09:33:41","date_gmt":"2024-11-26T01:33:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36425\/"},"modified":"2024-11-26T09:33:41","modified_gmt":"2024-11-26T01:33:41","slug":"java%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e8%b7%a8%e7%b1%bb%e4%bc%a0%e9%80%92%e5%8f%98%e9%87%8f%e5%80%bc%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36425\/","title":{"rendered":"Java\u4e2d\u5982\u4f55\u5b9e\u73b0\u8de8\u7c7b\u4f20\u9012\u53d8\u91cf\u503c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173114100379511.jpg\" class=\"aligncenter\" title=\"Java\u4e2d\u5982\u4f55\u5b9e\u73b0\u8de8\u7c7b\u4f20\u9012\u53d8\u91cf\u503c\uff1f\u63d2\u56fe\" alt=\"Java\u4e2d\u5982\u4f55\u5b9e\u73b0\u8de8\u7c7b\u4f20\u9012\u53d8\u91cf\u503c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>java\u4e2d\u8de8\u7c7b\u4f20\u9012\u53d8\u91cf\u503c<\/strong><\/p>\n<p>\u5728java\u5f00\u53d1\u4e2d\uff0c\u6709\u65f6\u9700\u8981\u5c06\u67d0\u4e2a\u53d8\u91cf\u7684\u503c\u4ece\u4e00\u4e2a\u7c7b\u4f20\u9012\u5230\u53e6\u4e00\u4e2a\u7c7b\u7684\u7279\u5b9a\u65b9\u6cd5\u5185\u3002<\/p>\n<p>\u4e3a\u4e86\u5b9e\u73b0\u6b64\u76ee\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u65b9\u6cd51\uff1a\u4f7f\u7528\u8fd4\u56de\u65b9\u6cd5<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u5728\u88ab\u8c03\u7528\u7684\u7c7b\u4e2d\uff0c\u521b\u5efa\u8fd4\u56de\u53d8\u91cf\u503c\u7684getter\u65b9\u6cd5\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u5728\u8c03\u7528\u7c7b\u4e2d\u8c03\u7528\u6b64\u65b9\u6cd5\u6765\u83b7\u53d6\u7d22\u5f15\u503c\u3002<\/p>\n<pre>\/\/ \u88ab\u8c03\u7528\u7c7ba\npublic class a {\n    private int index;\n\n    public void setindex(int index) {\n        this.index = index;\n    }\n\n    public int getindex() {\n        return index;\n    }\n}\n\n\/\/ \u8c03\u7528\u7c7b\npublic class main {\n    public static void main(string[] args) {\n        a a = new a();\n        a.setindex(5);\n\n        \/\/ \u83b7\u53d6index\u503c\n        int index = a.getindex();\n        \/\/ ...\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd52\uff1a\u4f7f\u7528\u56de\u8c03\u51fd\u6570<\/strong><\/p>\n<p>\u5728\u8c03\u7528\u7c7b\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u94a9\u5b50\u51fd\u6570\uff08\u56de\u8c03\u51fd\u6570\uff09\uff0c\u5c06\u8be5\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u88ab\u8c03\u7528\u7684\u7c7b\u3002\u5f53\u88ab\u8c03\u7528\u7684\u7c7b\u5b8c\u6210\u64cd\u4f5c\u540e\uff0c\u5b83\u53ef\u4ee5\u8c03\u7528\u94a9\u5b50\u51fd\u6570\u5c06\u7d22\u5f15\u503c\u4f20\u9012\u56de\u8c03\u7528\u7c7b\u3002<\/p>\n<pre>\/\/ \u88ab\u8c03\u7528\u7c7bA\npublic class A {\n    private int index;\n\n    public void find(String text, String target, IndexCallback callback) {\n        \/\/ ...\n        if (index != -1) {\n            callback.onIndexFound(index);\n        }\n    }\n\n    public interface IndexCallback {\n        void onIndexFound(int index);\n    }\n}\n\n\/\/ \u8c03\u7528\u7c7b\npublic class Main {\n    public static void main(String[] args) {\n        A a = new A();\n        a.find(\"Hello world\", \"world\", new IndexCallback() {\n            @Override\n            public void onIndexFound(int index) {\n                \/\/ \u83b7\u53d6index\u503c\n                \/\/ ...\n            }\n        });\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5176\u4ed6\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u9664\u4e86\u4ee5\u4e0a\u4e24\u79cd\u65b9\u6cd5\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5355\u4f8b\u6a21\u5f0f\u3001\u5168\u5c40\u53d8\u91cf\u6216\u6d88\u606f\u961f\u5217\u7b49\u5176\u4ed6\u6280\u672f\u6765\u5b9e\u73b0\u8de8\u7c7b\u53d8\u91cf\u4f20\u9012\u3002\u9009\u62e9\u6700\u5408\u9002\u7684\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u573a\u666f\u7684\u9700\u6c42\u548c\u9650\u5236\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava\u4e2d\u5982\u4f55\u5b9e\u73b0\u8de8\u7c7b\u4f20\u9012\u53d8\u91cf\u503c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>java\u4e2d\u8de8\u7c7b\u4f20\u9012\u53d8\u91cf\u503c \u5728java\u5f00\u53d1\u4e2d\uff0c\u6709\u65f6\u9700\u8981\u5c06\u67d0\u4e2a\u53d8\u91cf\u7684\u503c\u4ece\u4e00\u4e2a\u7c7b\u4f20\u9012\u5230\u53e6\u4e00\u4e2a\u7c7b\u7684\u7279\u5b9a\u65b9\u6cd5\u5185\u3002 \u4e3a\u4e86\u5b9e\u73b0\u6b64\u76ee\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u65b9\u6cd51\uff1a\u4f7f\u7528\u8fd4\u56de\u65b9\u6cd5 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5728\u88ab\u8c03\u7528\u7684\u7c7b\u4e2d\uff0c\u521b\u5efa\u8fd4\u56de\u53d8\u91cf\u503c\u7684getter\u65b9\u6cd5\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u5728\u8c03\u7528\u7c7b\u4e2d\u8c03\u7528\u6b64\u65b9\u6cd5\u6765\u83b7\u53d6\u7d22\u5f15\u503c\u3002 \/\/ \u88ab\u8c03\u7528\u7c7ba public class a { private int index; public void setindex(int index) { this.index = index; } public int getindex() { return index; } } \/\/ \u8c03\u7528\u7c7b public class main { public static void main(string[] args) { a a = new a(); a.setindex(5); \/\/ \u83b7\u53d6index\u503c int index = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-36425","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=36425"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36425\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}