{"id":225266,"date":"2020-12-01T18:18:29","date_gmt":"2020-12-01T10:18:29","guid":{"rendered":"http:\/\/4563.org\/?p=225266"},"modified":"2020-12-01T18:18:29","modified_gmt":"2020-12-01T10:18:29","slug":"%e5%a6%82%e6%9e%9c%e8%a6%81%e5%88%9b%e5%bb%ba%e4%b8%80%e4%b8%aa%e6%b3%9b%e5%9e%8b%e6%95%b0%e7%bb%84%ef%bc%8c%e8%af%a5%e6%80%8e%e4%b9%88%e5%81%9a%e6%af%94%e8%be%83%e5%a5%bd%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=225266","title":{"rendered":"\u5982\u679c\u8981\u521b\u5efa\u4e00\u4e2a\u6cdb\u578b\u6570\u7ec4\uff0c\u8be5\u600e\u4e48\u505a\u6bd4\u8f83\u597d\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5982\u679c\u8981\u521b\u5efa\u4e00\u4e2a\u6cdb\u578b\u6570\u7ec4\uff0c\u8be5\u600e\u4e48\u505a\u6bd4\u8f83\u597d\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhao1014 <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u76f4\u63a5\u5f3a\u8f6c\u6210\u6cdb\u578b\u6570\u7ec4\u5417\uff1f\u7c7b\u4f3c\u4e8e\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code>private final T[] array; public ClassName(int length){  \/\/\u8fd9\u91cc\u7f16\u8bd1\u5668\u4f1a\u6709\u8b66\u544a  array = (T[])new Object[length]; } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4556610\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chocovon <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Effective Java \u91cc\u8bb2\u8fc7\u5e94\u907f\u514d\u4f7f\u7528\u6cdb\u578b\u6570\u7ec4\uff0c\u7528 List \u4ee3\u66ff                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4556611\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : OldCarMan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8211; \u53c2\u7167\uff0cArrays \u7684 copyOf \u65b9\u6cd5\uff1a<\/p>\n<p>&#8220;`javascript<br \/> public static &lt;T&gt; T[] newArray(int length, Class&lt;? extends T[]&gt; type) {<br \/> return ((Object) type == (Object) Object[].class) ? (T[]) new Object[length] : (T[])Array.newInstance(type.getComponentType(), length);<br \/> }<br \/>&#8220;`<br \/>&#8211; \u4f7f\u7528<\/p>\n<p>&#8220;`javascript<br \/>Integer[] integers = newArray(10, Integer[].class);<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4556612\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : OldCarMan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             (\u2299\ufe4f\u2299) sorry\uff0c\u56de\u590d\u4e0d\u652f\u6301 md \u5417\uff1f\u597d\u50cf\u4e5f\u5220\u4e0d\u4e86\uff0c\u4f60\u8bb2\u7a76\u770b\u5427\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4556613\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hdfg159 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u76f4\u63a5 object \u5927\u6cd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4556614\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : janus77 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u81ea\u5df1\u5199\u4e00\u4e2a\u6570\u636e\u7ed3\u6784                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4556615\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SoloCompany <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u5fd8\u8bb0\u5728\u54ea\u91cc\u7684\u8ba8\u8bba java \u7684 Type[] \u5c31\u662f\u4e00\u4e2a design flaw, \u76f4\u63a5\u5bfc\u81f4\u4e86\u548c\u540e\u6765\u7684\u6cdb\u578b\u7cfb\u7edf\u4e0d\u517c\u5bb9<\/p>\n<p>\u8981\u540c\u65f6\u4f7f\u7528\u6cdb\u578b\u548c\u6570\u7ec4\u90a3\u5c31\u53ea\u80fd\u4f7f\u7528 Object[], \u5bf9\u4e8e\u6cdb\u578b T, T[] \u5b9e\u9645\u7c7b\u578b\u5c31\u662f Object[]                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4556616\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SoloCompany <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53e6\u5916\u4e00\u4e2a\u53ef\u4ee5\u53c2\u8003\u7684\u4f8b\u5b50<\/p>\n<p>https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/stream\/Stream.html#toArray-java.util.function.IntFunction-<\/p>\n<p>\u65b9\u6cd5\u7b7e\u540d<br \/>&lt;A&gt; A[] toArray(IntFunction&lt;A[]&gt; generator)<\/p>\n<p>\u4f7f\u7528<br \/>SomeType[] typedArray = someStreamtoArray(SomeType[]::new);                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u8981\u521b\u5efa\u4e00\u4e2a\u6cdb\u578b\u6570\u7ec4\uff0c\u8be5\u600e\u4e48\u505a\u6bd4&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/225266"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=225266"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/225266\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=225266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=225266"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=225266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}