{"id":76,"date":"2018-03-24T20:32:55","date_gmt":"2018-03-24T11:32:55","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=76"},"modified":"2018-03-25T12:11:49","modified_gmt":"2018-03-25T03:11:49","slug":"%e3%80%90java%e3%83%aa%e3%83%95%e3%82%a1%e3%82%af%e3%82%bf%e3%83%aa%e3%83%b3%e3%82%b0%e3%80%91%e3%81%9d%e3%81%ae3%ef%bc%9anull%e3%83%8c%e3%83%ab%e3%82%aa%e3%83%96%e3%82%b8%e3%82%a7%e3%82%af%e3%83%88","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=76","title":{"rendered":"\u3010Java\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3011\u305d\u306e3\uff1a\u8131\u306c\u308b\u307d!(Null(\u30cc\u30eb)\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u6d3b\u7528)"},"content":{"rendered":"<p>NullPointerException(\u306c\u308b\u307d)\u306fJava\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u306f\u3064\u304d\u7269\u3067\u3059\u304c\u3001\u305d\u308c\u304c\u767a\u751f\u3057\u306a\u3044\u3088\u3046\u306a\u624b\u6cd5\u306f\u3044\u304f\u3064\u304b\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u305d\u306e\u65b9\u6cd5\u306e\u4e00\u3064\u306b\u300c\u30cc\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u300d\u3092\u4f7f\u3046\u3068\u3044\u3046\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre>\u308f\u304b\u308a\u3084\u3059\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306eNull\u5bfe\u7b56\u3057\u3066\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u6319\u3052\u3089\u308c\u307e\u3059\u3088\u306d\u3002<\/pre>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nInputForm input = new InputForm();\r\n\r\nInputCondition condition = input.get(&quot;\u592a\u90ce&quot;);\r\n\r\n\/\/\u901a\u5e38\u306eNull\u30c1\u30a7\u30c3\u30af\r\nif(condition!=null){\r\n\r\n\u3000\u3000\u3000\u3000condition.display_name();\r\n}\r\n\r\n <\/pre>\n<p>\u3082\u3057\u304f\u306f\u3001Null\u53ca\u3073\u3001\u7a7a\u6587\u5b57\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5171\u901a\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u6210\u3055\u308c\u308b\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3082\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u306d\u3002\uff08\u3068\u3044\u3046\u304b\u305d\u308c\u304c\u57fa\u672c\uff1f\uff09<\/p>\n<p>\u305b\u3063\u304b\u304f\u306a\u306e\u3067\u3001\u300c\u30cc\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u300d\u3092\u4f7f\u3063\u3066Null\u30c1\u30a7\u30c3\u30af\u3092\u3055\u305b\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u4eca\u56de\u3054\u7d39\u4ecb\u3055\u305b\u3066\u9802\u304f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f\u3001\u56f3(\u30af\u30e9\u30b9\u56f3)\u306b\u3059\u308b\u3068\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u300cnulltest\u300d\u306f\u4eca\u56de\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u3067\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-112\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/03\/\u7e67\uff6f\u7e5d\uff69\u7e67\uff79\u8757\uff73_null.png\" alt=\"\" width=\"602\" height=\"267\" \/><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-115\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/03\/\u7e67\uff6f\u7e5d\uff69\u7e67\uff79\u8757\uff73_null.png\" alt=\"\" width=\"602\" height=\"267\" \/><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-115\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/03\/_null-e1521939645719.png\" alt=\"\" width=\"501\" height=\"222\" \/><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class Main {\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\tInputForm input = new InputForm();\r\n\r\n\t\tInputCondition condition = input.get(&quot;\u592a\u90ce&quot;);\r\n\r\n\t\tcondition.display_name();\r\n\r\n    }\r\n}\r\n<\/pre>\n<p>\u3053\u3061\u3089\u306e\u3001\u30b3\u30fc\u30c9\u304c\u300cinput.get(\"\u592a\u90ce\")\u300d\u3067\u3042\u308c\u3070\u3001\u300c\u540d\u524d\u306f\u592a\u90ce\u3067\u3059\u3002\u300d\u3068\u8fd4\u3057\u3001\u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306f\u3001\u4f55\u3082\u8868\u793a\u3057\u306a\u304f\u306a\u308a\u3001NullPointerException\u304c\u767a\u751f\u3057\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\r\npublic class InputForm {\r\n\r\n    public InputCondition get(String name) {\r\n\r\n    \tif(name.equals(&quot;\u592a\u90ce&quot;)){\r\n        \treturn new InputCondition(&quot;\u592a\u90ce&quot;);\r\n    \t}else{\r\n    \t\treturn NullInputCondition.getInstance();\r\n    \t}\r\n\r\n    }\r\n\r\n}\r\n\r\n<\/pre>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\r\npublic class InputCondition {\r\n\r\n\t\/\/\u540d\u524d\r\n\tprivate String name;\r\n\r\n\t\/\/\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\r\n\tpublic InputCondition(String name) {\r\n        this.name = name;\r\n\t}\r\n\r\n\tpublic void display_name() {\r\n        System.out.println(&quot;\u540d\u524d\u306f&quot; + name + &quot;\u3067\u3059\u3002&quot;);\r\n    }\r\n\r\n}\r\n\r\n<\/pre>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\r\n\/\/InputCondition\u3092\u7d99\u627f\r\n\r\npublic class NullInputCondition extends InputCondition{\r\n\r\n    \/\/\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u751f\u6210\r\n    private static NullInputCondition nullInputCondition = new NullInputCondition();\r\n\r\n\t\/\/\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\r\n\tpublic NullInputCondition() {\r\n\t\tsuper(&quot;&quot;);\r\n\t}\r\n\r\n    \/\/\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u53d6\u5f97\r\n    public static NullInputCondition getInstance() {\r\n        return nullInputCondition;\r\n    }\r\n\r\n\t\/\/\u4f55\u3082\u3057\u306a\u3044\u3002\r\n\tpublic void display_name() {\r\n    }\r\n\r\n}\r\n\r\n<\/pre>\n<p>InputCondition\u3092\u7d99\u627f\u3055\u305b\u305f\u300cNullInputCondition\u300d\u3068\u3044\u3046\u30af\u30e9\u30b9\u3092\u4f5c\u308a\u3001\u300cdisplay_name()\u300d\u3092\u7d99\u627f\u3055\u305b\u3066Null\u306e\u5834\u5408\u306f\u3001\u4f55\u3082\u3057\u306a\u3044\u3068\u3044\u3046\u5f62\u3067\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u300c\u30cc\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u300d\u3092\u4f7f\u7528\u3059\u308b\u30e1\u30ea\u30c3\u30c8\u3068\u3057\u3066\u306f\u4e0b\u8a18\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u30e1\u30a4\u30f3\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u3044\u3061\u3044\u3061Null\u3092\u610f\u8b58\u3057\u306a\u304f\u3066\u6e08\u3080\u306e\u3067\u53ef\u8aad\u6027\u304c\u5411\u4e0a\u3059\u308b\u3002<\/li>\n<\/ul>\n<p>\u305f\u3060\u3001\u30c7\u30e1\u30ea\u30c3\u30c8\u3068\u3057\u3066\u306f\u3001\u4e0b\u8a18\u304c\u6319\u3052\u3089\u308c\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<ul>\n<li>\u305d\u3082\u305d\u3082\u3001\u5b9f\u88c5\u8005\u4ee5\u5916\u304c\u3001\u8a72\u5f53\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u300c\u30cc\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u300d\u304c\u3042\u308b\u304b\u3069\u3046\u304b\u6c17\u3065\u304b\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002<\/li>\n<li>\u7d50\u5c40\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5074\u3067Null\u30c1\u30a7\u30c3\u30af\u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/li>\n<\/ul>\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u7d50\u5c40Null\u30c1\u30a7\u30c3\u30af\u3092\u66f8\u304b\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3068\u306f\u8a00\u3048\u3001<strong>\u4e00\u3064\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5bfe\u3059\u308bNull\u30c1\u30a7\u30c3\u30af\u304c\u7570\u5e38\u306b\u591a\u3044\u5834\u5408<\/strong>\u7b49\u306b\u306f\u304b\u306a\u308a\u6709\u52b9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>Null\u30c1\u30a7\u30c3\u30af\u306e\u3057\u5fd8\u308c\u9632\u6b62\u3084\u3001\u305d\u3082\u305d\u3082\u3081\u3093\u3069\u304f\u3055\u3044\u3068\u8a00\u3063\u305f\u5834\u5408\u3082\u3001\u30cc\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306a\u3089\u95a2\u4fc2\u306a\u3044\u3067\u3059\u304b\u3089\u306d\u3002\u3046\u307e\u304f\u4f7f\u3044\u5206\u3051\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"NullPointerException(\u306c\u308b\u307d)\u306fJava\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u306f\u3064\u304d\u7269\u3067\u3059\u304c\u3001\u305d\u308c\u304c\u767a\u751f\u3057\u306a\u3044\u3088\u3046\u306a\u624b\u6cd5\u306f\u3044\u304f\u3064\u304b\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u305d\u306e\u65b9\u6cd5\u306e\u4e00\u3064\u306b\u300c\u30cc\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u300d\u3092\u4f7f\u3046\u3068\u3044\u3046\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002 \u308f\u304b\u308a\u3084 [&hellip;]","protected":false},"author":1,"featured_media":86,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/76"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=76"}],"version-history":[{"count":20,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":124,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/76\/revisions\/124"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/86"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}