{"id":64963,"date":"2026-01-24T11:24:36","date_gmt":"2026-01-24T03:24:36","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/64963.html"},"modified":"2026-01-24T11:24:36","modified_gmt":"2026-01-24T03:24:36","slug":"java%e5%9f%ba%e7%a1%80-%e6%b3%9b%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/64963.html","title":{"rendered":"Java\u57fa\u7840\u2014\u2014\u6cdb\u578b"},"content":{"rendered":"<p>\u672c\u6587\u8bb2\u8ff0\u6cdb\u578b\u7684\u6982\u5ff5\u3001\u6cdb\u578b\u7684\u5e94\u7528\u573a\u666f&#xff0c;\u8ba9\u6211\u4eec\u66f4\u4e86\u89e3\u6cdb\u578b\u7684\u4f5c\u7528<\/p>\n<hr \/>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E4%B8%80%E3%80%81%E6%B3%9B%E5%9E%8B%E7%9A%84%E6%A6%82%E5%BF%B5-toc\" style=\"margin-left:40px\">\u4e00\u3001\u6cdb\u578b\u7684\u6982\u5ff5<\/p>\n<p id=\"1%E3%80%81%E4%BB%80%E4%B9%88%E6%98%AF%E6%B3%9B%E5%9E%8B-toc\" style=\"margin-left:80px\">1\u3001\u4ec0\u4e48\u662f\u6cdb\u578b<\/p>\n<p id=\"2%E3%80%81%E6%B3%9B%E5%9E%8B%E7%9A%84%E5%A5%BD%E5%A4%84-toc\" style=\"margin-left:80px\">2\u3001\u6cdb\u578b\u7684\u597d\u5904<\/p>\n<p id=\"3%E3%80%81%E6%B3%9B%E5%9E%8B%E7%9A%84%E7%9B%B8%E5%85%B3%E5%90%8D%E8%AF%8D-toc\" style=\"margin-left:80px\">3\u3001\u6cdb\u578b\u7684\u76f8\u5173\u540d\u8bcd<\/p>\n<p id=\"4%E3%80%81%E7%B1%BB%E5%9E%8B%E5%8F%98%E9%87%8F%3CT%3E%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF-toc\" style=\"margin-left:80px\">4\u3001\u7c7b\u578b\u53d8\u91cf<\/p>\n<p>   \u7684\u5e94\u7528\u573a\u666f\n  <\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E6%B3%9B%E5%9E%8B%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF-toc\" style=\"margin-left:40px\">\u4e8c\u3001\u6cdb\u578b\u7684\u5e94\u7528\u573a\u666f<\/p>\n<p id=\"1%E3%80%81%E6%B3%9B%E5%9E%8B%E7%B1%BB%E4%B8%8E%E6%B3%9B%E5%9E%8B%E6%8E%A5%E5%8F%A3-toc\" style=\"margin-left:80px\">1\u3001\u6cdb\u578b\u7c7b\u4e0e\u6cdb\u578b\u63a5\u53e3<\/p>\n<p id=\"2%E3%80%81%E6%B3%9B%E5%9E%8B%E6%96%B9%E6%B3%95-toc\" style=\"margin-left:80px\">2\u3001\u6cdb\u578b\u65b9\u6cd5<\/p>\n<p id=\"3%E3%80%81%E7%B1%BB%E5%9E%8B%E9%80%9A%E9%85%8D%E7%AC%A6-toc\" style=\"margin-left:80px\">3\u3001\u7c7b\u578b\u901a\u914d\u7b26<\/p>\n<p id=\"3.1%E3%80%81%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E9%80%9A%E9%85%8D%E7%AC%A6-toc\" style=\"margin-left:120px\">3.1\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u901a\u914d\u7b26<\/p>\n<p id=\"3.2%E3%80%81%E4%BD%9C%E7%94%A8-toc\" style=\"margin-left:120px\">3.2\u3001\u4f5c\u7528<\/p>\n<p id=\"3.3%E3%80%81%E7%B1%BB%E5%9E%8B%E9%80%9A%E9%85%8D%E7%AC%A6%E7%9A%84%E5%88%86%E7%B1%BB-toc\" style=\"margin-left:120px\">3.3\u3001\u7c7b\u578b\u901a\u914d\u7b26\u7684\u5206\u7c7b<\/p>\n<p id=\"3.4%E3%80%81%E4%B8%8A%E9%99%90%E9%80%9A%E9%85%8D%E7%AC%A6-toc\" style=\"margin-left:120px\">3.4\u3001\u4e0a\u9650\u901a\u914d\u7b26<\/p>\n<p id=\"3.5%E3%80%81%E4%B8%8B%E9%99%90%E9%80%9A%E9%85%8D%E7%AC%A6-toc\" style=\"margin-left:120px\">3.5\u3001\u4e0b\u9650\u901a\u914d\u7b26<\/p>\n<p id=\"%E4%B8%89%E3%80%81%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0-toc\" style=\"margin-left:40px\">\u4e09\u3001\u53ef\u53d8\u53c2\u6570<\/p>\n<p id=\"1%E3%80%81%E6%A0%BC%E5%BC%8F-toc\" style=\"margin-left:80px\">1\u3001\u683c\u5f0f<\/p>\n<p id=\"2%E3%80%81%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF-toc\" style=\"margin-left:80px\">2\u3001\u53ef\u53d8\u53c2\u6570\u7684\u5e94\u7528\u573a\u666f<\/p>\n<p id=\"%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:40px\">\u603b\u7ed3<\/p>\n<hr id=\"hr-toc\" \/>\n<h3 id=\"%E4%B8%80%E3%80%81%E6%B3%9B%E5%9E%8B%E7%9A%84%E6%A6%82%E5%BF%B5\">\u4e00\u3001\u6cdb\u578b\u7684\u6982\u5ff5<\/h3>\n<h4 id=\"1%E3%80%81%E4%BB%80%E4%B9%88%E6%98%AF%E6%B3%9B%E5%9E%8B\">1\u3001\u4ec0\u4e48\u662f\u6cdb\u578b<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4f8b\u5982&#xff1a;\u751f\u4ea7\u74f6\u5b50\u7684\u5382\u5bb6&#xff0c;\u4e00\u5f00\u59cb\u5e76\u4e0d\u77e5\u9053\u6211\u4eec\u5c06\u6765\u4f1a\u7528\u74f6\u5b50\u88c5\u4ec0\u4e48&#xff0c;\u6211\u4eec\u4ec0\u4e48\u90fd\u53ef\u4ee5\u88c5&#xff0c;\u4f46\u662f\u6709\u7684\u65f6\u5019&#xff0c;\u6211\u4eec\u5728\u4f7f\u7528\u65f6&#xff0c;\u60f3\u8981\u9650\u5b9a\u67d0\u4e2a\u74f6\u5b50\u53ea\u80fd\u7528\u6765\u88c5\u4ec0\u4e48&#xff0c;\u8fd9\u6837\u6211\u4eec\u4e0d\u4f1a\u88c5\u9519&#xff0c;\u800c\u7528\u7684\u65f6\u5019\u4e5f\u53ef\u4ee5\u653e\u5fc3\u7684\u4f7f\u7528&#xff0c;\u65e0\u9700\u518d\u4e09\u601d\u91cf\u3002\u6211\u4eec\u751f\u6d3b\u4e2d\u662f\u5728\u4f7f\u7528\u8fd9\u4e2a\u74f6\u5b50\u65f6\u5728\u74f6\u5b50\u4e0a\u201c\u8d34\u6807\u7b7e\u201d&#xff0c;\u8fd9\u6837\u5c31\u8f7b\u677e\u89e3\u51b3\u4e86\u95ee\u9898\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6cdb\u578b\u662fJDK 5.0\u5f15\u5165\u7684\u7279\u6027&#xff0c;\u5141\u8bb8\u5728\u5b9a\u4e49\u7c7b\u3001\u63a5\u53e3\u6216\u65b9\u6cd5\u65f6\u4f7f\u7528\u7c7b\u578b\u53c2\u6570\u3002\u6cdb\u578b\u7684\u6838\u5fc3\u76ee\u7684\u662f\u63d0\u9ad8\u4ee3\u7801\u590d\u7528\u6027&#xff0c;\u540c\u65f6\u589e\u5f3a\u7c7b\u578b\u5b89\u5168\u6027\u548c\u51cf\u5c11\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u7684\u9700\u8981\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;java.lang.Comparable\u63a5\u53e3\u548cjava.util.Comparator\u63a5\u53e3&#xff0c;\u662f\u7528\u4e8e\u5bf9\u8c61\u6bd4\u8f83\u5927\u5c0f\u7684\u89c4\u8303\u63a5\u53e3&#xff0c;\u8fd9\u4e24\u4e2a\u63a5\u53e3\u53ea\u662f\u9650\u5b9a\u4e86\u5f53\u4e00\u4e2a\u5bf9\u8c61\u5927\u4e8e\u53e6\u4e00\u4e2a\u5bf9\u8c61\u65f6\u8fd4\u56de\u6b63\u6574\u6570&#xff0c;\u5c0f\u4e8e\u8fd4\u56de\u8d1f\u6574\u6570&#xff0c;\u7b49\u4e8e\u8fd4\u56de0\u3002\u4f46\u662f\u5e76\u4e0d\u786e\u5b9a\u662f\u4ec0\u4e48\u7c7b\u578b\u7684\u5bf9\u8c61\u6bd4\u8f83\u5927\u5c0f&#xff0c;\u4e4b\u524d\u7684\u65f6\u5019\u53ea\u80fd\u7528Object\u7c7b\u578b\u8868\u793a&#xff0c;\u4f7f\u7528\u65f6\u65e2\u9ebb\u70e6\u53c8\u4e0d\u5b89\u5168&#xff0c;\u56e0\u6b64JDK1.5\u5c31\u7ed9\u5b83\u4eec\u589e\u52a0\u4e86\u6cdb\u578b\u3002<\/p>\n<p>public interface Comparable&lt;T&gt;{ \u00a0 \u00a0 int compareTo(T o) ; }<\/p>\n<p>public interface Comparator&lt;T&gt;{ \u00a0 \u00a0 \u00a0int compare(T o1, T o2) ; }<\/p>\n<p>\u5176\u4e2d&lt;T&gt;\u5c31\u662f\u7c7b\u578b\u53c2\u6570&#xff0c;\u5373\u6cdb\u578b\u3002<\/p>\n<h4 id=\"2%E3%80%81%E6%B3%9B%E5%9E%8B%E7%9A%84%E5%A5%BD%E5%A4%84\">2\u3001\u6cdb\u578b\u7684\u597d\u5904<\/h4>\n<p>public class GenericInterfaceTest {<br \/>\n    public static void main(String[] args) {<br \/>\n        Object o &#061; new GenericImpl1().show(&#034;2&#034;);<br \/>\n        System.out.println(((String)o).length());\/\/\u5f3a\u8f6c<\/p>\n<p>\/\/        new GenericImpl2().show(&#034;2&#034;)\/\/\u62a5\u9519<br \/>\n        Integer show &#061; new GenericImpl2().show(2);\/\/\u65e0\u9700\u5f3a\u8f6c<br \/>\n    }<br \/>\n}<br \/>\ninterface GenericInterface&lt;T&gt;{<br \/>\n    T show(T t);<br \/>\n}<br \/>\nclass GenericImpl1 implements GenericInterface{\/\/\u65e0\u9650\u5b9a\u7c7b\u578b<br \/>\n    &#064;Override<br \/>\n    public Object show(Object o) {<br \/>\n        return o;<br \/>\n    }<br \/>\n}<br \/>\nclass GenericImpl2 implements GenericInterface&lt;Integer&gt;{\/\/\/\u9650\u5b9a\u7c7b\u578b\u4e3aInteger<br \/>\n    &#064;Override<br \/>\n    public Integer show(Integer integer) {<br \/>\n        return integer;<br \/>\n    }<br \/>\n} <\/p>\n<ul>\n<li>\n<p>\u7c7b\u578b\u5b89\u5168&#xff1a;\u7f16\u8bd1\u65f6\u68c0\u67e5\u7c7b\u578b&#xff0c;\u907f\u514d\u8fd0\u884c\u65f6 ClassCastException<\/p>\n<\/li>\n<li>\n<p>\u4ee3\u7801\u7b80\u6d01&#xff1a;\u65e0\u9700\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362<\/p>\n<\/li>\n<li>\n<p>\u793a\u4f8b\u5bf9\u6bd4&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u65e0\u6cdb\u578b&#xff1a;\u9700\u8981 (String) o\u5f3a\u5236\u8f6c\u6362<\/p>\n<\/li>\n<li>\n<p>\u6709\u6cdb\u578b&#xff1a;\u76f4\u63a5\u4f7f\u7528 <font face=\"monospace\">Integer o<\/font>&#xff0c;\u7f16\u8bd1\u5668\u786e\u4fdd\u7c7b\u578b\u6b63\u786e<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4 id=\"3%E3%80%81%E6%B3%9B%E5%9E%8B%E7%9A%84%E7%9B%B8%E5%85%B3%E5%90%8D%E8%AF%8D\">3\u3001\u6cdb\u578b\u7684\u76f8\u5173\u540d\u8bcd<\/h4>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\">\n<tbody>\n<tr>\n<td>\u7c7b\u578b\u53d8\u91cf&#xff08;Type Variables&#xff09;<\/td>\n<td>\u4ee3\u8868\u672a\u77e5\u7684\u6570\u636e\u7c7b\u578b<\/td>\n<td>\n<p>&lt;T&gt;, &lt;E&gt;&#xff0c;&lt;K,V&gt;\u7b49<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570\u5316\u7c7b\u578b&#xff08;Parameterized Types&#xff09;<\/td>\n<td>\u5df2\u6307\u5b9a\u7c7b\u578b\u53c2\u6570\u7684\u7c7b\/\u63a5\u53e3<\/td>\n<td>Comparator&lt;String&gt;<\/td>\n<\/tr>\n<tr>\n<td>\u6cdb\u5316\u7684\u6570\u7ec4\u7c7b\u578b&#xff08;GenericArrayType&#xff09;<\/td>\n<td>\u4ee3\u8868\u672a\u77e5\u7684\u6570\u7ec4\u7c7b\u578b<\/td>\n<td>T[ ]<\/td>\n<\/tr>\n<tr>\n<td>\u901a\u914d\u7b26\u7c7b\u578b&#xff08;WildcardType&#xff09;<\/td>\n<td>\u8868\u793a\u672a\u77e5\u7c7b\u578b<\/td>\n<td>Comparator&lt;?&gt;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4 id=\"4%E3%80%81%E7%B1%BB%E5%9E%8B%E5%8F%98%E9%87%8F%3CT%3E%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF\">4\u3001\u7c7b\u578b\u53d8\u91cf&lt;T&gt;\u7684\u5e94\u7528\u573a\u666f<\/h4>\n<ul>\n<li>\u58f0\u660e\u7c7b\u6216\u63a5\u53e3\u65f6&#xff0c;\u5728\u7c7b\u540d\u6216\u63a5\u53e3\u540d\u540e\u9762\u58f0\u660e\u7c7b\u578b\u53d8\u91cf&#xff0c;\u6211\u4eec\u628a\u8fd9\u6837\u7684\u7c7b\u6216\u63a5\u53e3\u79f0\u4e3a\u6cdb\u578b\u7c7b\u6216\u6cdb\u578b\u63a5\u53e3<\/li>\n<\/ul>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u3010\u4fee\u9970\u7b26\u3011 class \u7c7b\u540d&lt;\u7c7b\u578b\u53d8\u91cf\u5217\u8868&gt; \u3010extends \u7236\u7c7b\u3011 \u3010implements \u7236\u63a5\u53e3\u4eec\u3011{ \u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u3010\u4fee\u9970\u7b26\u3011 interface \u63a5\u53e3\u540d&lt;\u7c7b\u578b\u53d8\u91cf\u5217\u8868&gt; \u3010implements \u7236\u63a5\u53e3\u4eec\u3011{ \u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4f8b\u5982&#xff1a; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public class ArrayList&lt;E&gt; \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public interface Map&lt;K,V&gt;{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 &#8230;. \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/p>\n<ul>\n<li>\u58f0\u660e\u65b9\u6cd5\u65f6&#xff0c;\u5728\u3010\u4fee\u9970\u7b26\u3011\u4e0e\u8fd4\u56de\u503c\u7c7b\u578b\u4e4b\u95f4\u58f0\u660e\u7c7b\u578b\u53d8\u91cf&#xff0c;\u6211\u4eec\u628a\u58f0\u660e&#xff08;\u662f&lt;font color&#061;&#039;red&#039;&gt;\u58f0\u660e&lt;\/font&gt;\u4e0d\u662f\u5355\u7eaf\u7684\u4f7f\u7528&#xff09;\u4e86\u7c7b\u578b\u53d8\u91cf\u7684\u65b9\u6cd5\u79f0\u4e3a\u6cdb\u578b\u65b9\u6cd5<\/li>\n<\/ul>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u3010\u4fee\u9970\u7b26\u3011 &lt;\u7c7b\u578b\u53d8\u91cf\u5217\u8868&gt; \u8fd4\u56de\u503c\u7c7b\u578b \u65b9\u6cd5\u540d(\u3010\u5f62\u53c2\u5217\u8868\u3011)\u3010throws \u5f02\u5e38\u5217\u8868\u3011{ \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/&#8230; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4f8b\u5982&#xff1a;java.util.Arrays\u7c7b\u4e2d\u7684 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public static &lt;T&gt; List&lt;T&gt; asList(T&#8230; a){ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 &#8230;. \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/p>\n<h3 id=\"%E4%BA%8C%E3%80%81%E6%B3%9B%E5%9E%8B%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF\">\u4e8c\u3001\u6cdb\u578b\u7684\u5e94\u7528\u573a\u666f<\/h3>\n<h4 id=\"1%E3%80%81%E6%B3%9B%E5%9E%8B%E7%B1%BB%E4%B8%8E%E6%B3%9B%E5%9E%8B%E6%8E%A5%E5%8F%A3\">1\u3001\u6cdb\u578b\u7c7b\u4e0e\u6cdb\u578b\u63a5\u53e3<\/h4>\n<p>\u6cdb\u578b\u7c7b\u683c\u5f0f&#xff1a;<\/p>\n<p>\u4fee\u9970\u7b26\u00a0 class\u00a0 \u7c7b\u540d&lt;\u7c7b\u578b&gt; { }<\/p>\n<p>\u6cdb\u578b\u63a5\u53e3\u683c\u5f0f&#xff1a;<\/p>\n<p>\u4fee\u9970\u7b26\u00a0 interface\u00a0 \u63a5\u53e3\u540d&lt;\u7c7b\u578b&gt; { }<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u81ea\u4eceJDK1.5\u5f15\u5165\u6cdb\u578b\u7684\u6982\u5ff5\u4e4b\u540e&#xff0c;\u5bf9\u4e4b\u524d\u6838\u5fc3\u7c7b\u5e93\u4e2d\u7684API\u505a\u4e86\u5f88\u5927\u7684\u4fee\u6539&#xff0c;\u4f8b\u5982&#xff1a;\u96c6\u5408\u6846\u67b6\u96c6\u4e2d\u7684\u76f8\u5173\u63a5\u53e3\u548c\u7c7b\u3001java.lang.Comparable\u63a5\u53e3\u3001java.util.Comparator\u63a5\u53e3\u3001Class\u7c7b\u7b49\u7b49\u3002<\/p>\n<p>\u4e0b\u9762\u4ee5Collection\u3001ArrayList\u96c6\u5408\u4ee5\u53caIterator\u8fed\u4ee3\u5668\u4e3a\u4f8b\u6f14\u793a&#xff0c;\u6cdb\u578b\u7c7b\u4e0e\u6cdb\u578b\u63a5\u53e3\u7684\u4f7f\u7528\u3002<\/p>\n<p>import java.util.Arrays;<\/p>\n<p>public class TestRectangle {<br \/>\n    public static void main(String[] args) {<br \/>\n        Rectangle[] arr &#061; new Rectangle[4];<br \/>\n        arr[0] &#061; new Rectangle(6,2);<br \/>\n        arr[1] &#061; new Rectangle(4,3);<br \/>\n        arr[2] &#061; new Rectangle(12,1);<br \/>\n        arr[3] &#061; new Rectangle(5,4);<br \/>\n        System.out.println(&#034;\u6392\u5e8f\u4e4b\u524d&#xff1a;&#034;);<br \/>\n        for (Rectangle rectangle : arr) {<br \/>\n            System.out.println(rectangle);<br \/>\n        }<br \/>\n        Arrays.sort(arr);<br \/>\n        System.out.println(&#034;\u6392\u5e8f\u4e4b\u540e&#xff1a;&#034;);<br \/>\n        for (Rectangle rectangle : arr) {<br \/>\n            System.out.println(rectangle);<br \/>\n        }<br \/>\n    }<br \/>\n}<br \/>\nclass Rectangle implements Comparable&lt;Rectangle&gt;{<br \/>\n    private double length;<br \/>\n    private double width;<br \/>\n    public Rectangle(double length, double width) {<br \/>\n        this.length &#061; length;<br \/>\n        this.width &#061; width;<br \/>\n    }<\/p>\n<p>    public double getLength() {<br \/>\n        return length;<br \/>\n    }<\/p>\n<p>    public void setLength(double length) {<br \/>\n        this.length &#061; length;<br \/>\n    }<\/p>\n<p>    public double getWidth() {<br \/>\n        return width;<br \/>\n    }<\/p>\n<p>    public void setWidth(double width) {<br \/>\n        this.width &#061; width;<br \/>\n    }<\/p>\n<p>    public double area(){<br \/>\n        return length * width;<br \/>\n    }<\/p>\n<p>    public double perimeter(){<br \/>\n        return 2 * (length &#043; width);<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public String toString() {<br \/>\n        return &#034;Rectangle{&#034; &#043;<br \/>\n                &#034;length&#061;&#034; &#043; length &#043;<br \/>\n                &#034;, width&#061;&#034; &#043; width &#043;<br \/>\n                &#034;,area &#061;&#034; &#043; area() &#043;<br \/>\n                &#034;,perimeter &#061; &#034; &#043; perimeter() &#043;<br \/>\n                &#039;}&#039;;<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public int compareTo(Rectangle o) {<br \/>\n        int compare &#061; Double.compare(area(), o.area());<br \/>\n        return compare !&#061; 0 ? compare : Double.compare(perimeter(),o.perimeter());<br \/>\n    }<br \/>\n}<\/p>\n<h4 id=\"2%E3%80%81%E6%B3%9B%E5%9E%8B%E6%96%B9%E6%B3%95\">2\u3001\u6cdb\u578b\u65b9\u6cd5<\/h4>\n<p>\u683c\u5f0f&#xff1a;<\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\u4fee\u9970\u7b26\u00a0 &lt;\u7c7b\u578b&gt;\u00a0 \u8fd4\u56de\u503c\u7c7b\u578b\u00a0 \u65b9\u6cd5\u540d(\u7c7b\u578b\u00a0 \u53d8\u91cf\u540d){ }<\/p>\n<p>public class GenericMethodTest {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/\u4e0d\u4f7f\u7528\u6cdb\u578b<br \/>\n        String[] strArr &#061; {&#034;\u5b59\u884c\u8005&#034;,&#034;\u8005\u884c\u5b59&#034;,&#034;\u884c\u8005\u5b59&#034;};<br \/>\n        Object e &#061; new GenericMenthod().getElementNoGeneric(strArr,2);<br \/>\n        System.out.println(e);<br \/>\n        System.out.println(((String)e).length());<br \/>\n\/\/        \u4f7f\u7528\u6cdb\u578b<br \/>\n        Integer[] intArr &#061; {2,6,1};<br \/>\n        Integer element &#061; new GenericMenthod().getElement(intArr, 1);<br \/>\n        System.out.println(element);<br \/>\n    }<br \/>\n}<br \/>\nclass GenericMenthod{<br \/>\n    \/**<br \/>\n     * \u8fd4\u56de\u6307\u5b9a\u7d22\u5f15\u4f4d\u7f6e\u5143\u7d20<br \/>\n     *\/<br \/>\n    public Object getElementNoGeneric(Object[] array,int index){<br \/>\n        return array[index];<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u8fd4\u56de\u6307\u5b9a\u7d22\u5f15\u4f4d\u7f6e\u5143\u7d20<br \/>\n     *\/<br \/>\n    public &lt;T&gt; T getElement(T[] array,int index){<br \/>\n        return array[index];<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"3%E3%80%81%E7%B1%BB%E5%9E%8B%E9%80%9A%E9%85%8D%E7%AC%A6\">3\u3001\u7c7b\u578b\u901a\u914d\u7b26<\/h4>\n<h5 id=\"3.1%E3%80%81%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E9%80%9A%E9%85%8D%E7%AC%A6\">3.1\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u901a\u914d\u7b26<\/h5>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0List&lt;Number&gt; list &#061; new ArrayList&lt;Integer&gt;(); \/\/\u7f16\u8bd1\u9519\u8bef&#xff1a;\u6cdb\u578b\u4e0d\u652f\u6301\u591a\u6001<\/p>\n<h5 id=\"3.2%E3%80%81%E4%BD%9C%E7%94%A8\" style=\"margin-left:0px;margin-right:0px;text-align:justify\">3.2\u3001\u4f5c\u7528<\/h5>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e3a\u4e86\u8868\u793a\u5404\u79cd\u6cdb\u578bList\u7684\u7236\u7c7b&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u7c7b\u578b\u901a\u914d\u7b26<\/p>\n<h5 id=\"3.3%E3%80%81%E7%B1%BB%E5%9E%8B%E9%80%9A%E9%85%8D%E7%AC%A6%E7%9A%84%E5%88%86%E7%B1%BB\" style=\"margin-left:0px;margin-right:0px;text-align:justify\">3.3\u3001\u7c7b\u578b\u901a\u914d\u7b26\u7684\u5206\u7c7b<\/h5>\n<ul>\n<li style=\"text-align: justify\">\u7c7b\u578b\u901a\u914d\u7b26&#xff1a;&lt;?&gt;<\/li>\n<\/ul>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0List&lt;?&gt;&#xff1a;\u8868\u793a\u5143\u7d20\u7c7b\u578b\u672a\u77e5\u7684List&#xff0c;\u5b83\u7684\u5143\u7d20\u53ef\u4ee5\u5339\u914d\u4efb\u4f55\u7684\u7c7b\u578b<\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u8fd9\u79cd\u5e26\u901a\u914d\u7b26\u7684List\u4ec5\u8868\u793a\u5b83\u662f\u5404\u79cd\u6cdb\u578bList\u7684\u7236\u7c7b&#xff0c;\u5e76\u4e0d\u80fd\u628a\u5143\u7d20\u6dfb\u52a0\u5230\u5176\u4e2d\u00a0<\/p>\n<ul>\n<li style=\"text-align: justify\">\u7c7b\u578b\u4e0a\u9650\u901a\u914d\u7b26&#xff1a;&lt;? extends \u7c7b\u578b&gt;<\/li>\n<\/ul>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 List&lt;? extends Number&gt;&#xff1a;\u5b83\u8868\u793a\u7684\u7c7b\u578b\u662fNumber\u6216\u8005\u5176\u5b50\u7c7b\u578b\u00a0<\/p>\n<ul>\n<li style=\"text-align:justify\">\u7c7b\u578b\u4e0b\u9650\u901a\u914d\u7b26&#xff1a;&lt;? super \u7c7b\u578b&gt;<\/li>\n<\/ul>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 List&lt;? super Number&gt;&#xff1a;\u5b83\u8868\u793a\u7684\u7c7b\u578b\u662fNumber\u6216\u8005\u5176\u7236\u7c7b\u578b<\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\u6848\u4f8b&#xff1a;<\/p>\n<p>public class GenericTest {<br \/>\n    public static void main(String[] args) {<br \/>\n        System.out.println(&#034;&#8212;&#8212;&#8212;-\u7c7b\u578b\u901a\u914d\u7b26&#xff1a;&lt;?&gt;&#034;);<br \/>\n        List&lt;?&gt; list1 &#061; new ArrayList&lt;Object&gt;();<br \/>\n        List&lt;?&gt; list2 &#061; new ArrayList&lt;Number&gt;();<br \/>\n        List&lt;?&gt; list3 &#061; new ArrayList&lt;Integer&gt;();<br \/>\n        \/\/list1.add(3);\/\/\u7f16\u8bd1\u4e0d\u901a\u8fc7<br \/>\n    }<br \/>\n}<\/p>\n<h5 id=\"3.4%E3%80%81%E4%B8%8A%E9%99%90%E9%80%9A%E9%85%8D%E7%AC%A6\">3.4\u3001\u4e0a\u9650\u901a\u914d\u7b26<\/h5>\n<p>List&lt;?\u00a0 extends\u00a0 Number&gt; list &#061; new ArrayList&lt;Integer&gt;();<\/p>\n<p>import java.util.ArrayList;<br \/>\nimport java.util.List;<\/p>\n<p>public class GenericExtendsTest {<br \/>\n    public static void main(String[] args) {<br \/>\n        List&lt;? extends Number&gt; list &#061; new ArrayList&lt;&gt;();<br \/>\n\/\/        list.get(1);\/\/\u7f16\u8bd1\u901a\u8fc7<br \/>\n\/\/        list.add(1);\/\/\u7f16\u8bd1\u4e0d\u901a\u8fc7&#xff0c;\u6cdb\u578b\u4ee3\u8868\u786e\u5b9a\u7684\u7c7b\u578b&#xff0c;&#xff1f;\u4ee3\u8868\u4e0d\u786e\u5b9a\u7c7b\u578b<br \/>\n        List&lt;Integer&gt; list1 &#061; new ArrayList&lt;&gt;();<br \/>\n        list1.add(1);<br \/>\n        list1.add(2);<br \/>\n        list1.add(3);<br \/>\n        printElement(list1);<br \/>\n    }<\/p>\n<p>    \/\/\u8be5\u65b9\u6cd5\u80fd\u63a5\u6536\u7684\u53c2\u6570&#xff1a;Number\u7684\u5b50\u7c7b<br \/>\n    private static void printElement(List&lt;? extends Number&gt; list) {<br \/>\n        for (Number number : list) {<br \/>\n            System.out.println(number);<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h5 id=\"3.5%E3%80%81%E4%B8%8B%E9%99%90%E9%80%9A%E9%85%8D%E7%AC%A6\">3.5\u3001\u4e0b\u9650\u901a\u914d\u7b26<\/h5>\n<p>List&lt;?\u00a0 super\u00a0 Number&gt; list &#061; new ArrayList&lt;Integer&gt;();<\/p>\n<p>import java.util.ArrayList;<br \/>\nimport java.util.List;<\/p>\n<p>public class GenericSuperTest {<br \/>\n    public static void main(String[] args) {<br \/>\n        List&lt;? super Integer&gt; list &#061; new ArrayList&lt;&gt;();<br \/>\n\/\/        list.add(1);\/\/\u7f16\u8bd1\u901a\u8fc7<br \/>\n\/\/        Object object &#061; list.get(1);\/\/\u8bfb\u4e0d\u592a\u597d\u7528<\/p>\n<p>        List&lt;Integer&gt; list1 &#061; new ArrayList&lt;&gt;();<br \/>\n        addElement(list1,2);<br \/>\n        System.out.println(list1);<br \/>\n        List&lt;? super Integer&gt; list2 &#061; new ArrayList&lt;&gt;();<br \/>\n        addElement1(list2,2);<br \/>\n        System.out.println(list2);<br \/>\n    }<\/p>\n<p>    \/\/list\u63a5\u6536\u7684\u6570\u636e\u7c7b\u578b&#xff08;&gt;&#061;Integer&#xff09;<br \/>\n    private static void addElement(List&lt;? super Integer&gt; list, Integer e) {<br \/>\n        list.add(e);<br \/>\n    }<br \/>\n    \/\/list\u63a5\u6536\u6570\u636e\u7c7b\u578b&#xff08;&gt;&#061;T&#xff09;<br \/>\n    private static&lt;T&gt; void addElement1(List&lt;? super T&gt; list1, T e) {<br \/>\n        list1.add(e);<br \/>\n    }<br \/>\n}<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\">\n<tbody>\n<tr>\n<td style=\"width:136px\"><\/td>\n<td style=\"width:184px\">\u8bfb\u53d6\u80fd\u529b<\/td>\n<td style=\"width:140px\">\u5199\u5165\u80fd\u529b<\/td>\n<td style=\"width:130px\">\u4e3b\u8981\u7528\u9014<\/td>\n<td style=\"width:99px\">\u7c7b\u578b\u5b89\u5168<\/td>\n<\/tr>\n<tr>\n<td style=\"width:136px\">\u4e0a\u9650\u901a\u914d\u7b26&lt;? extends T&gt;<\/td>\n<td style=\"width:184px\">\u2705 \u53ef\u5b89\u5168\u8bfb\u53d6\u4e3a T \u7c7b\u578b<\/td>\n<td style=\"width:140px\">\n<p>\u200b<\/p>\n<p>\u274c \u57fa\u672c\u4e0d\u80fd\u5199\u5165 &#xff08;\u53ea\u80fd\u5199null&#xff09;<\/p>\n<\/td>\n<td style=\"width:130px\">\n<p>\u200b<\/p>\n<p>1. \u4ece\u96c6\u5408\u83b7\u53d6\u5143\u7d20\u5904\u7406 2. \u53ea\u8bfb\u64cd\u4f5c 3. \u751f\u4ea7\u6570\u636e\u4f9b\u4f7f\u7528<\/p>\n<\/td>\n<td style=\"width:99px\">\u8bfb\u53d6\u5b89\u5168<\/td>\n<\/tr>\n<tr>\n<td style=\"width:136px\">\u4e0b\u9650\u901a\u914d\u7b26&lt;? super T&gt;<\/td>\n<td style=\"width:184px\">\n<p>\u200b<\/p>\n<p>\u274c \u53ea\u80fd\u8bfb\u53d6\u4e3a Object \u7c7b\u578b<\/p>\n<\/td>\n<td style=\"width:140px\">\n<p>\u2705 \u53ef\u5199\u5165 T \u53ca\u5176\u5b50\u7c7b<\/p>\n<\/td>\n<td style=\"width:130px\">1. \u5411\u96c6\u5408\u6dfb\u52a0\u5143\u7d20 2. \u5199\u5165\u64cd\u4f5c 3. \u6d88\u8d39\u6570\u636e<\/td>\n<td style=\"width:99px\">\u5199\u5165\u5b89\u5168<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"%E4%B8%89%E3%80%81%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0\">\u4e09\u3001\u53ef\u53d8\u53c2\u6570<\/h3>\n<h4 id=\"1%E3%80%81%E6%A0%BC%E5%BC%8F\">1\u3001\u683c\u5f0f<\/h4>\n<p>\u4fee\u9970\u7b26\u00a0 \u8fd4\u56de\u503c\u7c7b\u578b\u00a0 \u65b9\u6cd5\u540d ( \u6570\u636e\u7c7b\u578b&#8230;\u00a0 \u53d8\u91cf\u540d){ }<\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\u6ce8\u610f&#xff1a;<\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">&#xff08;1&#xff09;\u8fd9\u91cc\u7684\u53d8\u91cf\u5176\u5b9e\u662f\u4e00\u4e2a\u6570\u7ec4<\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">&#xff08;2&#xff09;\u5982\u679c\u4e00\u4e2a\u65b9\u6cd5\u6709\u591a\u4e2a\u53c2\u6570&#xff0c;\u5305\u542b\u53ef\u53d8\u53c2\u6570&#xff0c;\u53ef\u53d8\u53c2\u6570\u8981\u653e\u5728\u6700\u540e<\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\u6848\u4f8b&#xff1a;<\/p>\n<p>public class ParamTest {<br \/>\n    public static void main(String[] args) {<br \/>\n        System.out.println(sum());<br \/>\n        System.out.println(sum(10));<br \/>\n        System.out.println(sum(10, 20));<br \/>\n        System.out.println(sum(10, 20, 30));<br \/>\n        System.out.println(sum(10, 20, 30, 40));<br \/>\n        int[] intArr &#061; {10, 20, 30, 40};<br \/>\n        System.out.println(sum(intArr));<br \/>\n    }<\/p>\n<p>    public static int sum(int&#8230; a) {<br \/>\n        int sum &#061; 0;<br \/>\n        for (int i : a) {<br \/>\n            sum &#043;&#061; i;<br \/>\n        }<br \/>\n        return sum;<br \/>\n    }<\/p>\n<p>    \/*public static int sum(int&#8230; a, int b) {<br \/>\n        return 0;<br \/>\n    }*\/<br \/>\n}<\/p>\n<h4 id=\"2%E3%80%81%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF\">2\u3001\u53ef\u53d8\u53c2\u6570\u7684\u5e94\u7528\u573a\u666f<\/h4>\n<ul>\n<li style=\"text-align:justify\">Arrays\u5de5\u5177\u7c7b&#xff1a;<\/li>\n<\/ul>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public static List asList(T&#8230; a)&#xff1a;\u8fd4\u56de\u7531\u6307\u5b9a\u6570\u7ec4\u652f\u6301\u7684\u56fa\u5b9a\u5927\u5c0f\u7684\u5217\u8868<\/p>\n<hr \/>\n<h3 id=\"%E6%80%BB%E7%BB%93\" style=\"margin-left:0px;margin-right:0px;text-align:justify\">\u603b\u7ed3<\/h3>\n<ul>\n<li>\n<p>\u6cdb\u578b\u672c\u8d28&#xff1a;\u7c7b\u578b\u53c2\u6570\u5316&#xff0c;\u5b89\u5168\u53c8\u7075\u6d3b<\/p>\n<\/li>\n<li>\n<p>\u901a\u914d\u7b26\u539f\u5219&#xff1a;<\/p>\n<ul>\n<li>\n<p>extends&#xff1a;\u80fd\u53d6\u4e0d\u80fd\u5b58<\/p>\n<\/li>\n<li>\n<p>super&#xff1a;\u80fd\u5b58\u4e0d\u80fd\u53d6<\/p>\n<\/li>\n<li>\n<p>&lt;?&gt;&#xff1a;\u53ea\u8bfb\u4e0d\u5199<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u53ef\u53d8\u53c2\u6570&#xff1a;\u7c7b\u578b\u540e\u52a0&#8230;&#xff0c;\u5fc5\u987b\u5728\u6700\u540e<\/p>\n<\/li>\n<li>\n<p>PECS\u539f\u5219&#xff1a;Producer Extends, Consumer Super<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u8bb2\u8ff0\u6cdb\u578b\u7684\u6982\u5ff5\u3001\u6cdb\u578b\u7684\u5e94\u7528\u573a\u666f&#xff0c;\u8ba9\u6211\u4eec\u66f4\u4e86\u89e3\u6cdb\u578b\u7684\u4f5c\u7528 \u76ee\u5f55<br \/>\n\u4e00\u3001\u6cdb\u578b\u7684\u6982\u5ff5<br \/>\n1\u3001\u4ec0\u4e48\u662f\u6cdb\u578b<br \/>\n2\u3001\u6cdb\u578b\u7684\u597d\u5904<br \/>\n3\u3001\u6cdb\u578b\u7684\u76f8\u5173\u540d\u8bcd<br \/>\n4\u3001\u7c7b\u578b\u53d8\u91cf\u7684\u5e94\u7528\u573a\u666f\u4e8c\u3001\u6cdb\u578b\u7684\u5e94\u7528\u573a\u666f<br \/>\n1\u3001\u6cdb\u578b\u7c7b\u4e0e\u6cdb\u578b\u63a5\u53e3<br \/>\n2\u3001\u6cdb\u578b\u65b9\u6cd5<br \/>\n3\u3001\u7c7b\u578b\u901a\u914d\u7b26<br \/>\n3.1\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u901a\u914d\u7b26<br \/>\n3.2\u3001\u4f5c\u7528<br \/>\n3.3\u3001\u7c7b\u578b\u901a\u914d\u7b26\u7684\u5206\u7c7b<br \/>\n3.4\u3001\u4e0a\u9650\u901a\u914d\u7b26<br \/>\n3.5\u3001\u4e0b\u9650\u901a\u914d\u7b26<br \/>\n\u4e09\u3001\u53ef\u53d8\u53c2\u6570<br \/>\n1\u3001\u683c\u5f0f<br \/>\n2\u3001\u53ef\u53d8\u53c2\u6570\u7684\u5e94\u7528\u573a\u666f<br \/>\n\u603b\u7ed3 \u4e00\u3001\u6cdb\u578b\u7684\u6982\u5ff5<br \/>\n1\u3001\u4ec0\u4e48\u662f\u6cdb\u578b \u4f8b\u5982&amp;#x<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,190],"topic":[],"class_list":["post-64963","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java\u57fa\u7840\u2014\u2014\u6cdb\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/64963.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u57fa\u7840\u2014\u2014\u6cdb\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u672c\u6587\u8bb2\u8ff0\u6cdb\u578b\u7684\u6982\u5ff5\u3001\u6cdb\u578b\u7684\u5e94\u7528\u573a\u666f&#xff0c;\u8ba9\u6211\u4eec\u66f4\u4e86\u89e3\u6cdb\u578b\u7684\u4f5c\u7528 \u76ee\u5f55 \u4e00\u3001\u6cdb\u578b\u7684\u6982\u5ff5 1\u3001\u4ec0\u4e48\u662f\u6cdb\u578b 2\u3001\u6cdb\u578b\u7684\u597d\u5904 3\u3001\u6cdb\u578b\u7684\u76f8\u5173\u540d\u8bcd 4\u3001\u7c7b\u578b\u53d8\u91cf\u7684\u5e94\u7528\u573a\u666f\u4e8c\u3001\u6cdb\u578b\u7684\u5e94\u7528\u573a\u666f 1\u3001\u6cdb\u578b\u7c7b\u4e0e\u6cdb\u578b\u63a5\u53e3 2\u3001\u6cdb\u578b\u65b9\u6cd5 3\u3001\u7c7b\u578b\u901a\u914d\u7b26 3.1\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u901a\u914d\u7b26 3.2\u3001\u4f5c\u7528 3.3\u3001\u7c7b\u578b\u901a\u914d\u7b26\u7684\u5206\u7c7b 3.4\u3001\u4e0a\u9650\u901a\u914d\u7b26 3.5\u3001\u4e0b\u9650\u901a\u914d\u7b26 \u4e09\u3001\u53ef\u53d8\u53c2\u6570 1\u3001\u683c\u5f0f 2\u3001\u53ef\u53d8\u53c2\u6570\u7684\u5e94\u7528\u573a\u666f \u603b\u7ed3 \u4e00\u3001\u6cdb\u578b\u7684\u6982\u5ff5 1\u3001\u4ec0\u4e48\u662f\u6cdb\u578b \u4f8b\u5982&amp;#x\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/64963.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-24T03:24:36+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/64963.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/64963.html\",\"name\":\"Java\u57fa\u7840\u2014\u2014\u6cdb\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-24T03:24:36+00:00\",\"dateModified\":\"2026-01-24T03:24:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/64963.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/64963.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/64963.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\u57fa\u7840\u2014\u2014\u6cdb\u578b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java\u57fa\u7840\u2014\u2014\u6cdb\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/64963.html","og_locale":"zh_CN","og_type":"article","og_title":"Java\u57fa\u7840\u2014\u2014\u6cdb\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u672c\u6587\u8bb2\u8ff0\u6cdb\u578b\u7684\u6982\u5ff5\u3001\u6cdb\u578b\u7684\u5e94\u7528\u573a\u666f&#xff0c;\u8ba9\u6211\u4eec\u66f4\u4e86\u89e3\u6cdb\u578b\u7684\u4f5c\u7528 \u76ee\u5f55 \u4e00\u3001\u6cdb\u578b\u7684\u6982\u5ff5 1\u3001\u4ec0\u4e48\u662f\u6cdb\u578b 2\u3001\u6cdb\u578b\u7684\u597d\u5904 3\u3001\u6cdb\u578b\u7684\u76f8\u5173\u540d\u8bcd 4\u3001\u7c7b\u578b\u53d8\u91cf\u7684\u5e94\u7528\u573a\u666f\u4e8c\u3001\u6cdb\u578b\u7684\u5e94\u7528\u573a\u666f 1\u3001\u6cdb\u578b\u7c7b\u4e0e\u6cdb\u578b\u63a5\u53e3 2\u3001\u6cdb\u578b\u65b9\u6cd5 3\u3001\u7c7b\u578b\u901a\u914d\u7b26 3.1\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u901a\u914d\u7b26 3.2\u3001\u4f5c\u7528 3.3\u3001\u7c7b\u578b\u901a\u914d\u7b26\u7684\u5206\u7c7b 3.4\u3001\u4e0a\u9650\u901a\u914d\u7b26 3.5\u3001\u4e0b\u9650\u901a\u914d\u7b26 \u4e09\u3001\u53ef\u53d8\u53c2\u6570 1\u3001\u683c\u5f0f 2\u3001\u53ef\u53d8\u53c2\u6570\u7684\u5e94\u7528\u573a\u666f \u603b\u7ed3 \u4e00\u3001\u6cdb\u578b\u7684\u6982\u5ff5 1\u3001\u4ec0\u4e48\u662f\u6cdb\u578b \u4f8b\u5982&amp;#x","og_url":"https:\/\/www.wsisp.com\/helps\/64963.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-24T03:24:36+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/64963.html","url":"https:\/\/www.wsisp.com\/helps\/64963.html","name":"Java\u57fa\u7840\u2014\u2014\u6cdb\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-24T03:24:36+00:00","dateModified":"2026-01-24T03:24:36+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/64963.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/64963.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/64963.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Java\u57fa\u7840\u2014\u2014\u6cdb\u578b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/64963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=64963"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/64963\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=64963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=64963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=64963"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=64963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}