{"id":442105,"date":"2021-04-19T09:22:43","date_gmt":"2021-04-19T01:22:43","guid":{"rendered":"http:\/\/4563.org\/?p=442105"},"modified":"2021-04-19T09:22:43","modified_gmt":"2021-04-19T01:22:43","slug":"%e5%85%b3%e4%ba%8e-java-%e4%b8%a4%e4%b8%aa-integer-%e7%9b%b8%e5%8a%a0%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=442105","title":{"rendered":"\u5173\u4e8e Java \u4e24\u4e2a Integer \u76f8\u52a0\u7684\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5173\u4e8e Java \u4e24\u4e2a Integer \u76f8\u52a0\u7684\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : pkookp8 <\/span>  <span><i><\/i> 13<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5c0f\u5f1f\u521a\u5f00\u59cb\u5b66 Java\uff0c\u4e86\u89e3\u5230 Java \u6ca1\u6709\u64cd\u4f5c\u7b26\u91cd\u8f7d \u6240\u4ee5\u4f7f\u7528+\u64cd\u4f5c\u7b26\u5bf9\u4e24\u4e2a\u7c7b\u8fdb\u884c\u76f8\u52a0\u5e94\u8be5\u662f\u505a\u4e0d\u5230\u7684<\/p>\n<p>\u4e8e\u662f\u5bf9\u8fd9\u6bb5\u4ee3\u7801\u4e0d\u662f\u5f88\u7406\u89e3\u4e86<\/p>\n<pre><code>class Integer {     private int value;      public Integer(int value) {         this.value = value;     }      public int intValue() {         return this.value;     }      public static Integer valueOf(int i) {         return new Integer(i);     } } public class Main {     public static void main(String[] argv)     {         java.lang.Integer zz = 1;         java.lang.Integer xx = 2;                   \/\/\u8c03\u7528 java.lang.Integer.valueOf(2)\uff0c\u8fd4\u56de java.lang.Integer.Integer \u7c7b\u578b          java.lang.Integer aa = zz + xx;          \/\/zz + xx \u662f\u5982\u4f55\u5b9e\u73b0\u7684?         System.out.printf(\"%sn\", aa);          \/\/printf \u7684\u65f6\u5019\u53ef\u4ee5\u76f4\u63a5\u628a aa \u6253\u5370\u51fa\u6765\uff0c\u8fd9\u53c8\u662f\u600e\u4e48\u505a\u5230\u7684\uff1f          \/\/Integer a = 1;                                \/\/Type mismatch: cannot convert from int to Integer         \/\/Integer x = Integer.valueOf(1);         \/\/Integer y = Integer.valueOf(2);         \/\/Integer z = x + y;                         \/\/The operator + is undefined for the argument type(s) Integer, Integer                                                                \/\/\u8bf7\u95ee\u5982\u4f55\u81ea\u5df1\u5b9e\u73b0 x+y?         \/\/System.out.printf(\"%sn\", z);       \/\/\u4f3c\u4e4e\u6253\u5370\u4e86\u5730\u5740, [email&#160;protected]      } } <\/code><\/pre>\n<p>\u5c1d\u8bd5\u7528\u4e86\u65ad\u70b9\u7684\u65b9\u5f0f\uff0c\u53d1\u73b0 zz + xx \u4f3c\u4e4e\u4f1a\u8fdb\u5165\u4e24\u6b21 java.lang.Integer.intValue \u51fd\u6570<\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4 zz \u8c03\u7528\u4e86 java.lang.Integer.intValue\uff0c\u8fd4\u56de\u4e86 int \u7c7b\u578b\u7684 1<\/p>\n<p>xx \u8fd4\u56de\u4e86 int \u7c7b\u578b\u7684 2<\/p>\n<p>\u7136\u540e\u8fdb\u5165\u4e86 java.lang.Integer.valueOf(3)<\/p>\n<p>printf \u7684\u65f6\u5019\u53ef\u4ee5\u76f4\u63a5\u628a aa \u6253\u5370\u51fa\u6765<\/p>\n<p>\u95ee\u9898<\/p>\n<ol>\n<li>java.lang.Integer \u662f\u600e\u4e48\u5b9e\u73b0 Integer a = 1;\u800c\u4e0d\u62a5\u9519\u201cType mismatch: cannot convert from int to Integer\u201d\u7684\uff1f<\/li>\n<li>java.lang.Integer \u53c8\u662f\u5982\u4f55\u5b9e\u73b0 x+y?<\/li>\n<li>java.lang.Integer \u8fd8\u80fd\u76f4\u63a5\u7528%s \u6253\u5370<\/li>\n<\/ol>\n<p>\u4e0d\u77e5\u9053\u7528\u4ec0\u4e48\u5173\u952e\u8bcd\u641c\u7d22\u8fd9\u4e9b\u95ee\u9898<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5650470\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yuanmomo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             1 Java \u91cc\u9762\u81ea\u52a8\u88c5\u7bb1\uff0c\u4f1a\u81ea\u52a8\u628a\u57fa\u672c\u7c7b\u578b\u8f6c\u6362\u6210\u5305\u88c5\u7c7b\u578b<\/p>\n<p>2 Java \u91cc\u9762\u7684\u81ea\u52a8\u62c6\u7bb1\uff0c\u4f1a\u81ea\u52a8\u628a\u5305\u88c5\u7c7b\u578b\u8f6c\u6362\u4e3a\u57fa\u672c\u7c7b\u578b\u3002<\/p>\n<p>3 %s \u8868\u793a\u6253\u5370\u6210\u5b57\u7b26\u4e32\uff0c\u4f1a\u81ea\u52a8\u8c03\u7528 tostring \u65b9\u6cd5\uff0c\u5c06\u8fd9\u4e2a\u5bf9\u8c61\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8e Java \u4e24\u4e2a Intege&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\/442105"}],"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=442105"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/442105\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=442105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=442105"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=442105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}