{"id":282,"date":"2026-07-21T11:02:02","date_gmt":"2026-07-21T03:02:02","guid":{"rendered":"http:\/\/ssjava.xyz\/index.php\/2026\/07\/19\/java-wrapper-class-complete-guide\/"},"modified":"2026-07-19T14:54:07","modified_gmt":"2026-07-19T06:54:07","slug":"27-%e5%8c%85%e8%a3%85%e7%b1%bb%e8%af%a6%e8%a7%a3%ef%bc%9a%e8%87%aa%e5%8a%a8%e8%a3%85%e7%ae%b1%e6%8b%86%e7%ae%b1%e3%80%81%e7%bc%93%e5%ad%98%e6%b1%a0%e4%b8%8e%e9%81%bf%e5%9d%91%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/ssjava.xyz\/index.php\/2026\/07\/21\/27-%e5%8c%85%e8%a3%85%e7%b1%bb%e8%af%a6%e8%a7%a3%ef%bc%9a%e8%87%aa%e5%8a%a8%e8%a3%85%e7%ae%b1%e6%8b%86%e7%ae%b1%e3%80%81%e7%bc%93%e5%ad%98%e6%b1%a0%e4%b8%8e%e9%81%bf%e5%9d%91%e6%8c%87%e5%8d%97\/","title":{"rendered":"27. \u5305\u88c5\u7c7b\u8be6\u89e3\uff1a\u81ea\u52a8\u88c5\u7bb1\u62c6\u7bb1\u3001\u7f13\u5b58\u6c60\u4e0e\u907f\u5751\u6307\u5357"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4e0a\u4e00\u7bc7\u6587\u7ae0\u6211\u4eec\u804a\u4e86\u679a\u4e3e\uff0c\u628a\u90a3\u4e9b\u56fa\u5b9a\u53d6\u503c\u7684\u4e1c\u897f\u53d8\u5b89\u5168\u4e86\u3002\u4f46\u8fd9\u8fd8\u4e0d\u591f\u2014\u2014\u4f60\u4f1a\u53d1\u73b0 Java \u91cc\u6709\u4e9b\u5f88\u57fa\u7840\u7684\u95ee\u9898\u4e00\u76f4\u9690\u9690\u4f5c\u75db\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>int<\/code> \u80fd\u653e\u8fdb <code>ArrayList&lt;Integer&gt;<\/code> \u5417\uff1f\u4e0d\u80fd\uff0c\u6cdb\u578b\u53ea\u80fd\u63a5\u5bf9\u8c61\u3002<\/li>\n\n\n\n<li><code>boolean<\/code> \u80fd\u8d4b\u503c\u4e3a <code>null<\/code> \u5417\uff1f\u4e0d\u80fd\uff0c\u57fa\u672c\u7c7b\u578b\u4e0d\u662f\u5f15\u7528\u3002<\/li>\n\n\n\n<li>\u90a3\u4f60\u5199<code>List&lt;int&gt;<\/code> \u8bd5\u8bd5\uff1f\u7f16\u8bd1\u5668\u76f4\u63a5\u9524\u4f60\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u89e3\u51b3\u57fa\u672c\u7c7b\u578b\u548c\u5bf9\u8c61\u7c7b\u578b\u4e4b\u95f4\u7684\u9e3f\u6c9f\uff0cJava \u7ed9\u6bcf\u79cd\u57fa\u672c\u7c7b\u578b\u914d\u4e86\u4e00\u4e2a\u300c\u5bf9\u8c61\u7248\u300d\u2014\u2014<strong>\u5305\u88c5\u7c7b\uff08Wrapper Class\uff09<\/strong>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u5305\u88c5\u7c7b\u5168\u5bb6\u798f<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u57fa\u672c\u7c7b\u578b<\/th><th>\u5305\u88c5\u7c7b<\/th><th>\u7236\u7c7b<\/th><\/tr><\/thead><tbody><tr><td><code>byte<\/code><\/td><td><code>Byte<\/code><\/td><td><code>Number<\/code><\/td><\/tr><tr><td><code>short<\/code><\/td><td><code>Short<\/code><\/td><td><code>Number<\/code><\/td><\/tr><tr><td><code>int<\/code><\/td><td><code>Integer<\/code><\/td><td><code>Number<\/code><\/td><\/tr><tr><td><code>long<\/code><\/td><td><code>Long<\/code><\/td><td><code>Number<\/code><\/td><\/tr><tr><td><code>float<\/code><\/td><td><code>Float<\/code><\/td><td><code>Number<\/code><\/td><\/tr><tr><td><code>double<\/code><\/td><td><code>Double<\/code><\/td><td><code>Number<\/code><\/td><\/tr><tr><td><code>char<\/code><\/td><td><code>Character<\/code><\/td><td><code>Object<\/code><\/td><\/tr><tr><td><code>boolean<\/code><\/td><td><code>Boolean<\/code><\/td><td><code>Object<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u4e86 <code>Character<\/code> \u548c <code>Boolean<\/code> \u76f4\u63a5\u7ee7\u627f <code>Object<\/code>\uff0c\u5269\u4e0b\u7684\u6570\u503c\u578b\u5305\u88c5\u7c7b\u90fd\u7ee7\u627f\u81ea <code>java.lang.Number<\/code> \u62bd\u8c61\u7c7b\u3002\u6240\u6709\u5305\u88c5\u7c7b\u90fd\u662f final \u7684\uff0c\u4e0d\u80fd\u7ee7\u627f\uff0c\u4e14\u90fd\u5b9e\u73b0\u4e86 <code>Serializable<\/code> \u548c <code>Comparable<\/code>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u88c5\u7bb1\u4e0e\u62c6\u7bb1<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u628a\u57fa\u672c\u7c7b\u578b\u53d8\u6210\u5305\u88c5\u7c7b\u53eb<strong>\u88c5\u7bb1<\/strong>\uff0c\u53cd\u8fc7\u6765\u53eb<strong>\u62c6\u7bb1<\/strong>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u624b\u52a8\u88c5\u7bb1\u62c6\u7bb1\uff08Java 5 \u4e4b\u524d\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u624b\u52a8\u88c5\u7bb1\uff1a\u57fa\u672c\u7c7b\u578b \u2192 \u5305\u88c5\u7c7b\nInteger i = Integer.valueOf(100);\n\/\/ \u6216\u8005\u7528\u6784\u9020\u65b9\u6cd5\uff08\u5df2\u5f03\u7528\uff0c\u522b\u7528\u4e86\uff09\n\/\/ Integer i = new Integer(100);  \/\/ \u274c \u4e0d\u63a8\u8350\n\n\/\/ \u624b\u52a8\u62c6\u7bb1\uff1a\u5305\u88c5\u7c7b \u2192 \u57fa\u672c\u7c7b\u578b\nint n = i.intValue();<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u81ea\u52a8\u88c5\u7bb1\u62c6\u7bb1\uff08Java 5+\uff09<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Java 5 \u5f15\u5165\u4e86\u81ea\u52a8\u88c5\u7bb1\u62c6\u7bb1\uff0c\u4ece\u6b64\u4f60\u53ef\u4ee5\u8fd9\u4e48\u5199\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer i = 100;          \/\/ \u81ea\u52a8\u88c5\u7bb1\uff1a\u7f16\u8bd1\u5668\u8c03\u7528\u4e86 Integer.valueOf(100)\nint n = i;                \/\/ \u81ea\u52a8\u62c6\u7bb1\uff1a\u7f16\u8bd1\u5668\u8c03\u7528\u4e86 i.intValue()\n\n\/\/ \u6df7\u5408\u8fd0\u7b97\nInteger a = 10;\nInteger b = 20;\nInteger c = a + b;        \/\/ a \u548c b \u81ea\u52a8\u62c6\u7bb1\u505a\u52a0\u6cd5\uff0c\u7ed3\u679c\u518d\u81ea\u52a8\u88c5\u7bb1\nSystem.out.println(c);    \/\/ 30<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u770b\u8d77\u6765\u5c31\u50cf <code>Integer<\/code> \u548c <code>int<\/code> \u53ef\u4ee5\u65e0\u7f1d\u6df7\u7528\u4e86\u3002\u4f46\u522b\u5fd8\u4e86\uff0c\u7f16\u8bd1\u5668\u5e2e\u4f60\u5728\u80cc\u540e\u63d2\u5165\u4e86 <code>valueOf()<\/code> \u548c <code>xxxValue()<\/code> \u8c03\u7528\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u81ea\u52a8\u88c5\u7bb1\u62c6\u7bb1\u662f\u4e2a\u8bed\u6cd5\u7cd6\uff0c\u4e0d\u662f\u8fd0\u884c\u65f6\u80fd\u529b\u3002\u4f60\u7f16\u8bd1\u51fa\u6765\u7684\u5b57\u8282\u7801\u91cc\uff0c\u8be5\u8c03\u7684\u65b9\u6cd5\u4e00\u4e2a\u4e0d\u5c11\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001Integer \u7f13\u5b58\u6c60\u2014\u2014\u4e00\u4e2a\u7ecf\u5178\u5927\u5751<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6765\u770b\u4e2a\u9762\u8bd5\u9898\u5e38\u5ba2\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer a = 127;\nInteger b = 127;\nSystem.out.println(a == b);     \/\/ true\n\nInteger c = 128;\nInteger d = 128;\nSystem.out.println(c == d);     \/\/ false \uff1f\uff1f\uff1f<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u662f\u4e0d\u662f\u89c9\u5f97 Java \u4e0d\u8bb2\u6b66\u5fb7\uff1f127 \u548c 128 \u5c31\u5dee 1 \u800c\u5df2\uff0c\u600e\u4e48\u7ed3\u679c\u5c31\u53cd\u8f6c\u4e86\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u539f\u56e0\u5728 <code>Integer.valueOf()<\/code> \u7684\u5b9e\u73b0\u91cc\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static Integer valueOf(int i) {\n    if (i &gt;= IntegerCache.low &amp;&amp; i &lt;= IntegerCache.high)\n        return IntegerCache.cache&#91;i + (-IntegerCache.low)];\n    return new Integer(i);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>IntegerCache<\/code> \u9ed8\u8ba4\u7f13\u5b58\u4e86 <strong>-128 \u5230 127<\/strong> \u4e4b\u95f4\u7684\u6240\u6709 Integer \u5bf9\u8c61\u3002\u5728\u8fd9\u4e2a\u8303\u56f4\u5185\uff0c<code>valueOf()<\/code> \u8fd4\u56de\u7684\u662f\u7f13\u5b58\u91cc\u7684\u540c\u4e00\u4e2a\u5bf9\u8c61\uff1b\u8d85\u51fa\u8fd9\u4e2a\u8303\u56f4\uff0c\u6bcf\u6b21\u8c03\u7528\u90fd\u4f1a new \u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u4ee5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>127 == 127<\/code> \u2192 \u4e24\u4e2a\u5f15\u7528\u6307\u5411\u7f13\u5b58\u4e2d\u7684\u540c\u4e00\u4e2a\u5bf9\u8c61 \u2192 <code>true<\/code><\/li>\n\n\n\n<li><code>128 == 128<\/code> \u2192 \u4e24\u4e2a\u4e0d\u540c\u7684\u65b0\u5bf9\u8c61 \u2192 <code>false<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u600e\u4e48\u907f\u514d\u8e29\u5751\uff1f<\/strong>\u6bd4\u8f83\u5305\u88c5\u7c7b\u6c38\u8fdc\u7528 <code>.equals()<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer a = 128;\nInteger b = 128;\nSystem.out.println(a.equals(b));  \/\/ true \u2705<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u8bb0\u4f4f\u4e00\u53e5\u8bdd\uff1a\u5305\u88c5\u7c7b\u6bd4\u8f83\u7528.equals()\uff0c\u57fa\u672c\u7c7b\u578b\u6bd4\u8f83\u7528==\u3002\u522b\u6df7\u7740\u6765\u3002<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u7c7b\u4f3c\u7684\u7f13\u5b58\u673a\u5236\u4e5f\u5b58\u5728\u5176\u4ed6\u5305\u88c5\u7c7b\u91cc\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Byte<\/code>\uff1a\u5168\u90e8\u7f13\u5b58\uff08-128~127\uff0c\u603b\u5171\u624d 256 \u4e2a\uff09<\/li>\n\n\n\n<li><code>Short<\/code>\uff1a-128~127<\/li>\n\n\n\n<li><code>Long<\/code>\uff1a-128~127<\/li>\n\n\n\n<li><code>Character<\/code>\uff1a0~127<\/li>\n\n\n\n<li><code>Integer<\/code>\uff1a-128~127\uff08\u53ef\u4ee5\u901a\u8fc7 JVM \u53c2\u6570\u8c03\u6574\u4e0a\u9650\uff09<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u7a7a\u6307\u9488\u9677\u9631\u2014\u2014\u81ea\u52a8\u62c6\u7bb1\u53ef\u80fd\u7ffb\u8f66<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u81ea\u52a8\u62c6\u7bb1\u770b\u7740\u65b9\u4fbf\uff0c\u4f46\u6709\u4e2a\u9690\u85cf\u6740\u624b\u2014\u2014<strong>NPE\uff08NullPointerException\uff09<\/strong>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer score = null;\nint realScore = score;  \/\/ \u7f16\u8bd1\u901a\u8fc7\uff0c\u8fd0\u884c\u629b NullPointerException\uff01\n\/\/ \u7b49\u4ef7\u4e8e int realScore = score.intValue();  \/\/ null.intValue() \u60f3\u60f3\u5c31\u77e5\u9053\u8981\u70b8<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6216\u8005\u66f4\u9690\u853d\u7684\u573a\u666f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5047\u8bbe\u4ece\u6570\u636e\u5e93\u67e5\u5230\u7684 count \u53ef\u80fd\u662f null\nInteger count = getCountFromDb();  \/\/ null\nif (count &gt; 0) {  \/\/ \u81ea\u52a8\u62c6\u7bb1 \u2192 NullPointerException\n    \/\/ \u8fd9\u884c\u90fd\u5230\u4e0d\u4e86\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7ecf\u9a8c\u6cd5\u5219\uff1a<\/strong>\u5305\u88c5\u7c7b\u53c2\u4e0e\u81ea\u52a8\u62c6\u7bb1\u64cd\u4f5c\u4e4b\u524d\uff0c\u5148\u5224\u7a7a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (count != null &amp;&amp; count &gt; 0) {\n    \/\/ \u5b89\u5168\u4e86\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u5b57\u7b26\u4e32\u4e0e\u5305\u88c5\u7c7b\u7684\u4e92\u8f6c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f00\u53d1\u4e2d\u7279\u522b\u5e38\u89c1\u7684\u9700\u6c42\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5b57\u7b26\u4e32 \u2192 \u57fa\u672c\u7c7b\u578b\nint n = Integer.parseInt(\"123\");\ndouble d = Double.parseDouble(\"3.14\");\nboolean b = Boolean.parseBoolean(\"true\");\n\n\/\/ \u5b57\u7b26\u4e32 \u2192 \u5305\u88c5\u7c7b\nInteger i = Integer.valueOf(\"123\");\nDouble dd = Double.valueOf(\"3.14\");\n\n\/\/ \u57fa\u672c\u7c7b\u578b\/\u5305\u88c5\u7c7b \u2192 \u5b57\u7b26\u4e32\nString s1 = Integer.toString(123);\nString s2 = String.valueOf(123);\nString s3 = 123 + \"\";         \/\/ \u5077\u61d2\u5199\u6cd5\uff0c\u7f16\u8bd1\u5668\u4f1a\u4f18\u5316<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f <code>parseXxx()<\/code> \u548c <code>valueOf()<\/code> \u7684\u533a\u522b\u2014\u2014\u524d\u8005\u8fd4\u56de\u57fa\u672c\u7c7b\u578b\uff0c\u540e\u8005\u8fd4\u56de\u5305\u88c5\u7c7b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int n = Integer.parseInt(\"123\");       \/\/ int\nInteger i = Integer.valueOf(\"123\");    \/\/ Integer<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001Number \u62bd\u8c61\u7c7b\u4e0e\u5e38\u7528\u65b9\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u516d\u4e2a\u6570\u503c\u578b\u5305\u88c5\u7c7b\u90fd\u7ee7\u627f\u81ea <code>Number<\/code> \u62bd\u8c61\u7c7b\uff0c\u6240\u4ee5\u5b83\u4eec\u90fd\u6709\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer i = 100;\nbyte b = i.byteValue();\nshort s = i.shortValue();\nint n = i.intValue();\nlong l = i.longValue();\nfloat f = i.floatValue();\ndouble d = i.doubleValue();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b\u65b9\u6cd5\u628a Integer \u8f6c\u6210\u522b\u7684\u6570\u503c\u7c7b\u578b\u3002\u6bd4\u5982\u4f60\u7528 <code>Integer<\/code> \u5b58\u4e86\u4e00\u4e2a int\uff0c\u4f46\u67d0\u4e2a\u65b9\u6cd5\u9700\u8981 <code>long<\/code>\uff0c\u76f4\u63a5 <code>.longValue()<\/code> \u5c31\u884c\uff0c\u4e0d\u7528\u4f60\u624b\u52a8\u5f3a\u8f6c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e03\u3001\u5305\u88c5\u7c7b\u7684\u5b9e\u9645\u7528\u9014\u603b\u7ed3<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u573a\u666f<\/th><th>\u8bf4\u660e<\/th><th>\u793a\u4f8b<\/th><\/tr><\/thead><tbody><tr><td>\u6cdb\u578b<\/td><td>\u6cdb\u578b\u53ea\u80fd\u4f7f\u7528\u5f15\u7528\u7c7b\u578b<\/td><td><code>List&lt;Integer&gt;<\/code> \u2705 <code>List&lt;int&gt;<\/code> \u274c<\/td><\/tr><tr><td>\u53ef\u4e3a null<\/td><td>\u5305\u88c5\u7c7b\u53ef\u4ee5\u8868\u793a\u300c\u672a\u8bbe\u7f6e\u300d<\/td><td>\u6570\u636e\u5e93\u5b57\u6bb5\u53ef\u80fd\u4e3a NULL<\/td><\/tr><tr><td>\u96c6\u5408\u6846\u67b6<\/td><td>\u96c6\u5408\u53ea\u80fd\u5b58\u5bf9\u8c61<\/td><td><code>Map&lt;String, Integer&gt;<\/code><\/td><\/tr><tr><td>\u5de5\u5177\u65b9\u6cd5<\/td><td>\u5305\u88c5\u7c7b\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u65b9\u6cd5<\/td><td><code>Integer.parseInt()<\/code><\/td><\/tr><tr><td>\u540c\u6b65\u9501<\/td><td>\u5305\u88c5\u7c7b\u5b9e\u4f8b\u53ef\u4f5c\u4e3a\u9501\u5bf9\u8c61<\/td><td>\u4f46\u8981\u6ce8\u610f\u7f13\u5b58\u6c60\u95ee\u9898<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u516b\u3001\u51e0\u4e2a\u5bb9\u6613\u7ffb\u8f66\u7684\u5c0f\u4f8b\u5b50<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">1. \u4e09\u5143\u8fd0\u7b97\u7b26\u7684\u7c7b\u578b\u63d0\u5347<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer a = null;\nint b = 1;\n\/\/ \u4e0b\u9762\u8fd9\u884c\u4f1a\u629b NPE\nint result = (a != null) ? a : b;\n\/\/ \u56e0\u4e3a\u4e09\u5143\u8fd0\u7b97\u7b26\u8981\u6c42\u4e24\u4e2a\u5206\u652f\u7684\u7c7b\u578b\u4e00\u81f4\uff0cb \u662f int\uff0ca \u4f1a\u88ab\u81ea\u52a8\u62c6\u7bb1\n\/\/ \u800c a \u662f null \u2192 NPE<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u5305\u88c5\u7c7b\u4f5c\u4e3a\u9501\u5bf9\u8c61<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>class Counter {\n    private Integer count = 0;\n\n    public void increment() {\n        synchronized (count) {   \/\/ \u274c \u5371\u9669\uff01\n            count++;  \/\/ count++ \u5b9e\u9645\u4e0a\u662f count = Integer.valueOf(count + 1)\n                      \/\/ \u6bcf\u6b21\u8d4b\u503c\u90fd\u521b\u5efa\u65b0\u5bf9\u8c61\uff0c\u9501\u7684\u4e0d\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61\uff01\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>count++<\/code> \u662f <code>count = Integer.valueOf(count + 1)<\/code> \u7684\u8bed\u6cd5\u7cd6\uff0c\u6bcf\u6b21\u90fd\u4f1a\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684 <code>Integer<\/code> \u5bf9\u8c61\u3002\u4f60\u9501\u7684 <code>count<\/code> \u53d8\u4e86\uff0c\u9501\u5c31\u5e9f\u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u6df7\u7528 int \u548c Integer \u65f6\u7684\u6027\u80fd<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u6b21\u88c5\u7bb1\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u5bf9\u8c61\uff08\u9664\u4e86\u7f13\u5b58\u8303\u56f4\u5185\u7684\uff09\uff0c\u5927\u91cf\u5faa\u73af\u91cc\u9891\u7e41\u88c5\u7bb1\u62c6\u7bb1\u4f1a\u6709\u6027\u80fd\u5f00\u9500\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u8fd9\u4e2a\u5faa\u73af\u5f88\u6162\u2014\u2014\u6bcf\u6b21\u52a0\u6cd5\u90fd\u8981\u88c5\u7bb1\u62c6\u7bb1\nInteger sum = 0;\nfor (int i = 0; i &lt; 10_000_000; i++) {\n    sum += i;  \/\/ \u88c5\u7bb1 1000 \u4e07\u6b21\n}\n\n\/\/ \u6539\u6210\u8fd9\u6837\u5c31\u5feb\u4e86\nint sum2 = 0;\nfor (int i = 0; i &lt; 10_000_000; i++) {\n    sum2 += i;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e5d\u3001\u7ed3\u8bed<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5305\u88c5\u7c7b\u4e0d\u662f\u4ec0\u4e48\u9ad8\u6df1\u7684\u4e1c\u897f\uff0c\u4f46\u5751\u4e0d\u5c11\u3002\u8bb0\u4f4f\u4e09\u6761\u51c6\u5219\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6bd4\u8f83\u7528 <code>.equals()<\/code>\uff0c\u522b\u56fe\u65b9\u4fbf\u7528 <code>==<\/code><\/li>\n\n\n\n<li>\u81ea\u52a8\u62c6\u7bb1\u524d\u8bb0\u5f97\u5224\u7a7a<\/li>\n\n\n\n<li>\u5927\u91cf\u6570\u503c\u8fd0\u7b97\u7528\u57fa\u672c\u7c7b\u578b\uff0c\u522b\u8ba9\u5305\u88c5\u7c7b\u62d6\u6162\u4f60\u7684\u7a0b\u5e8f<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5230\u8fd9\u7bc7\u4e3a\u6b62\uff0cJavaSE \u9762\u5411\u5bf9\u8c61\uff0803\uff09\u7684\u5168\u90e8\u5b50\u5206\u7c7b\u90fd\u5199\u5b8c\u4e86\u3002<code>static<\/code>\u3001\u5c01\u88c5\u3001\u7ee7\u627f\u3001\u62bd\u8c61\u7c7b\u3001\u591a\u6001\u3001\u63a5\u53e3\u3001\u5185\u90e8\u7c7b\u3001Object\u3001\u679a\u4e3e\u3001\u5305\u88c5\u7c7b\u2014\u2014\u6574\u6574 21 \u7bc7\u6587\u7ae0\uff0c\u628a Java \u9762\u5411\u5bf9\u8c61\u8fd9\u5757\u5543\u4e0b\u6765\u4e86\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u4e00\u7bc7\u6211\u4eec\u5c06\u8fdb\u5165 <strong>04. \u5f02\u5e38\u5904\u7406<\/strong>\uff0c\u804a\u804a <code>try-catch-finally<\/code>\u3001\u53d7\u68c0\u5f02\u5e38 vs \u8fd0\u884c\u65f6\u5f02\u5e38\u3001\u4ee5\u53ca\u81ea\u5b9a\u4e49\u5f02\u5e38\u7684\u90a3\u4e9b\u4e8b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u4e00\u7bc7\u6587\u7ae0\u6211\u4eec\u804a\u4e86\u679a\u4e3e\uff0c\u628a\u90a3\u4e9b\u56fa\u5b9a\u53d6\u503c\u7684\u4e1c\u897f\u53d8\u5b89\u5168\u4e86\u3002\u4f46\u8fd9\u8fd8\u4e0d\u591f\u2014\u2014\u4f60\u4f1a\u53d1\u73b0 Java \u91cc\u6709\u4e9b\u5f88\u57fa\u7840\u7684\u95ee\u9898\u4e00\u76f4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,72,9],"tags":[61,89,91,90,86],"class_list":["post-282","post","type-post","status-publish","format-standard","hentry","category-03-","category-08-enum-wrapper","category-java","tag-java","tag-javase","tag-91","tag-90","tag-86"],"_links":{"self":[{"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/posts\/282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=282"}],"version-history":[{"count":2,"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/posts\/282\/revisions"}],"predecessor-version":[{"id":297,"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/posts\/282\/revisions\/297"}],"wp:attachment":[{"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}