{"id":203247,"date":"2025-05-22T10:35:59","date_gmt":"2025-05-22T02:35:59","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203247\/"},"modified":"2025-05-22T10:35:59","modified_gmt":"2025-05-22T02:35:59","slug":"java%e4%b8%adobject%e8%bd%acdoubledouble%e7%9a%84null%e5%80%bc%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203247\/","title":{"rendered":"Java\u4e2dObject\u8f6cDouble(double)\u7684null\u503c\u5982\u4f55\u5904\u7406\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Java\u4e2dObject\u8f6cDouble(double)\u7684null\u503c\u5982\u4f55\u5904\u7406\uff1f<\/h1>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u5c31\u6574\u7406\u5206\u4eab\u300aJava\u4e2dObject\u8f6cDouble(double)\u7684null\u503c\u5982\u4f55\u5904\u7406\uff1f\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241102\/173055909667263c78cc948.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>java object\u8f6cdouble(double)\u7684null\u503c\u5904\u7406<\/strong><\/p>\n<p>\u95ee\u9898\u80cc\u666f\uff1a\u4f7f\u7528java\u5c06object\u7c7b\u578b\u8f6c\u6362\u4e3adouble(double)\u65f6\uff0c\u5bf9\u4e8enull\u503c\u7684\u60c5\u51b5\u5904\u7406\u5b58\u5728\u5dee\u5f02\u3002\u76f4\u63a5\u8f6c\u6362\u4e3adouble\u4f1a\u8fd4\u56denull\uff0c\u800c\u8f6c\u6362\u4e3adouble\u5219\u9700\u8981\u5224\u7a7a\u5e76\u8d4b\u4e88\u9ed8\u8ba4\u503c\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p><strong>1. \u76f4\u63a5\u8f6c\u6362\u4e3adouble\uff0c\u5e76\u5728\u4f7f\u7528\u524d\u8fdb\u884c\u5224\u7a7a\uff1a<\/strong><\/p>\n<pre>double d1 = (double) object;\nif (d1 == null) {\n  d1 = 0d; \/\/ \u8bbe\u7f6e\u9ed8\u8ba4\u503c\n}<\/pre>\n<p><strong>\u4f18\u70b9\uff1a<\/strong>\u5b9e\u73b0\u7b80\u5355\u3002<\/p>\n<p><strong>\u7f3a\u70b9\uff1a<\/strong>\u9700\u8981\u5728\u6bcf\u6b21\u4f7f\u7528d1\u524d\u8fdb\u884c\u5224\u7a7a\uff0c\u589e\u52a0\u4e86\u4ee3\u7801\u590d\u6742\u5ea6\u3002<\/p>\n<p><strong>2. \u4f7f\u7528\u5de5\u5177\u7c7b\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff1a<\/strong><\/p>\n<pre>public static Double parseDouble(Object object) {\n  return (Double) (object == null ? 0D : object);\n}\n\n\/\/ \u5728\u4e3b\u65b9\u6cd5\u4e2d\u8c03\u7528\u5de5\u5177\u7c7b\u65b9\u6cd5\nDouble d1 = parseDouble(object);<\/pre>\n<p><strong>\u4f18\u70b9\uff1a<\/strong>\u5c01\u88c5\u4e86\u7c7b\u578b\u8f6c\u6362\u903b\u8f91\uff0c\u63d0\u9ad8\u4e86\u4ee3\u7801\u53ef\u91cd\u7528\u6027\u3002<\/p>\n<p><strong>\u7f3a\u70b9\uff1a<\/strong>\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u989d\u5916\u7684\u5de5\u5177\u7c7b\u3002<\/p>\n<p><strong>\u9009\u62e9\u5efa\u8bae\uff1a<\/strong><\/p>\n<p>\u6839\u636e\u5177\u4f53\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li><strong>\u5bf9\u4e8e\u9700\u8981\u9891\u7e41\u4f7f\u7528double\u503c\uff1a<\/strong>\u4f7f\u7528\u76f4\u63a5\u8f6c\u6362\u5e76\u5224\u7a7a\u7684\u65b9\u6cd5\uff0c\u51cf\u5c11\u4ee3\u7801\u590d\u6742\u5ea6\u3002<\/li>\n<li><strong>\u5bf9\u4e8e\u9700\u8981\u4f7f\u7528double\u503c\u5c11\u91cf\u6b21\uff1a<\/strong>\u4f7f\u7528\u5de5\u5177\u7c7b\u65b9\u6cd5\uff0c\u63d0\u5347\u4ee3\u7801\u53ef\u7ef4\u62a4\u6027\u3002<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>double\u662fdouble\u7684\u5c01\u88c5\u7c7b\uff0c\u5141\u8bb8null\u3002<\/li>\n<li>double\u662f\u57fa\u672c\u7c7b\u578b\uff0c\u53ea\u5141\u8bb8\u5e38\u91cf\uff0c\u4e0d\u80fd\u4e3anull\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java\u4e2dObject\u8f6cDoub&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203247","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203247","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203247"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203247\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}