{"id":2129,"date":"2018-05-03T13:37:18","date_gmt":"2018-05-03T04:37:18","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=2129"},"modified":"2023-05-27T20:39:30","modified_gmt":"2023-05-27T11:39:30","slug":"%e3%80%90java%e3%80%91%e9%96%a2%e6%95%b0%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=2129","title":{"rendered":"\u3010Java\u3011\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8(Java8\u4ee5\u964d)"},"content":{"rendered":"<div class=\"graybox\"><span style=\"color: #ff0000;\"><strong>\u3053\u3053\u3067\u6271\u3046\u6982\u5ff5\u306f\u3001\u5c11\u3057\u96e3\u89e3\u306a\u6982\u5ff5\u306a\u306e\u3067\u3001\u3042\u305b\u3063\u3066\u7406\u89e3\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002Java\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306b\u306a\u308c\u3066\u3044\u306a\u3044\u65b9\u306f\u3001\u307e\u305a\u306fJava7\u307e\u3067\u306e\u57fa\u672c\u69cb\u6587\u3060\u3063\u305f\u308a\u3001\u696d\u52d9\u3067\u4f7f\u3063\u3066\u3044\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3084\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u77e5\u8b58\u304b\u3089\u5148\u306b\u5b66\u7fd2\u3055\u308c\u308b\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002<\/strong><\/span><\/div>\n<p>Java8\u304b\u3089\u3067\u3059\u304c\u3001<span style=\"color: #ff0000;\"><strong>\u95a2\u6570\u3092\u5909\u6570\u306b\u4ee3\u5165\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/strong><\/span><\/p>\n<h2>\u69cb\u6587<\/h2>\n<h3>static\u30e1\u30bd\u30c3\u30c9\u306e\u5834\u5408<\/h3>\n<pre class=\"lang:default decode:true\">\u5909\u6570\u540d=\u30af\u30e9\u30b9\u540d::\u305d\u306e\u30af\u30e9\u30b9\u306estatic\u30e1\u30bd\u30c3\u30c9<\/pre>\n<h3>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30e1\u30bd\u30c3\u30c9\u306e\u5834\u5408<\/h3>\n<pre class=\"lang:default decode:true\">\u5909\u6570\u540d = \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570\u540d::\u305d\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u30e1\u30bd\u30c3\u30c9\u540d<\/pre>\n<p>\u305f\u3060\u3001\u3053\u3053\u3067\u6ce8\u610f\u70b9\u304c\u3042\u308a\u307e\u3059\u3001<span style=\"color: #ff0000;\"><strong>\u4ee3\u5165\u3057\u305f\u3044\u95a2\u6570\u306e\u4ed5\u69d8\u306b\u5fdc\u3058\u3066\u3001\u4ee3\u5165\u3059\u308b\u5909\u6570\u306e\u578b\u304c\u6c7a\u307e\u3063\u3066\u3044\u308b<\/strong><\/span>\u306e\u3067\u3059\u3002<\/p>\n<h3>\u4ee3\u5165\u3067\u304d\u308b\u95a2\u6570\u306e\u6761\u4ef6<\/h3>\n<p>\u3042\u308b\u7279\u5b9a\u306e\u5f15\u6570\u3068\u623b\u308a\u5024\u3092\u6301\u3064\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u683c\u7d0d\u3067\u304d\u308b\u306e\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u305d\u306e\u5f15\u6570\u3068\u623b\u308a\u5024\u3092\u6301\u3064\u30e1\u30bd\u30c3\u30c9\u5ba3\u8a00\u3092\u542b\u3093\u3060SAM\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u306e\u307f<\/strong><\/span><\/p>\n<h4>SAM\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9(single-abstract-method interface)<\/h4>\n<p><span style=\"color: #ff0000;\"><strong>\u62bd\u8c61\u30e1\u30bd\u30c3\u30c9\u3092\u4e00\u3064\u3057\u304b\u542b\u307e\u306a\u3044\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9<\/strong><\/span>\u306e\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u5229\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><strong>\u62bd\u8c61\u30e1\u30bd\u30c3\u30c9\u3092\u4e00\u3064\u3057\u304b\u542b\u307e\u306a\u3044\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9<\/strong><\/p>\n<pre class=\"lang:default decode:true \">\/\/\u62bd\u8c61\u30e1\u30bd\u30c3\u30c9\u3092\u4e00\u3064\u3057\u304b\u542b\u307e\u306a\u3044\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\r\npublic interface Sam {\r\n\t\/\/\u62bd\u8c61\u30e1\u30bd\u30c3\u30c9\r\n\tpublic abstract int sum(int a,int b);\r\n}<\/pre>\n<p><strong>\u4f7f\u3044\u65b9<\/strong><\/p>\n<pre class=\"lang:default decode:true\">public class Main {\r\n\r\n\tpublic static int mainSum(int a,int b) {\r\n\t\treturn a + b;\r\n\t}\r\n\r\n\tpublic static void main(String args[]) {\r\n\t\tSam sam = Main::mainSum;\r\n\t\tSystem.out.println(sam.sum(3, 5));\r\n\r\n\t}\r\n\r\n}<\/pre>\n<p><strong>\u5b9f\u884c\u7d50\u679c<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2141\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8.png\" alt=\"\" width=\"278\" height=\"102\" \/><\/p>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306b\u3001<span style=\"color: #ff0000;\"><strong>\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9Sam\u306e\u4e2d\u306e\u300csum\u30e1\u30bd\u30c3\u30c9\u300d\u3068\u3001\u4ee3\u5165\u3057\u3066\u3044\u308bMain\u30af\u30e9\u30b9\u306e\u4e2d\u306e\u300cmainSum\u30e1\u30bd\u30c3\u30c9\u300d\u306e\u5f15\u6570\u3068\u623b\u308a\u5024\u306f\u5168\u304f\u540c\u3058<\/strong><\/span>\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u4ee3\u5165\u3057\u305f\u5909\u6570\u304b\u3089\u3001<span style=\"color: #ff0000;\"><strong>\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u969b\u306f\u3001\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u306e\u65b9\u306e\u540d\u524d\u3092\u4f7f\u3046<\/strong><\/span>\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u95a2\u6570\u3092\u683c\u7d0d\u3059\u308b\u305f\u3081\u306e\u6c4e\u7528SAM<\/h2>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306b\u3001<span style=\"color: #ff0000;\"><strong>\u62bd\u8c61\u30e1\u30bd\u30c3\u30c9\u3092\u4e00\u3064\u6301\u3064\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u7528\u610f\u3059\u308c\u3070\u3001\u95a2\u6570\u3092\u5909\u6570\u306b\u4ee3\u5165\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b<\/strong><\/span>\u3053\u3068\u306f\u308f\u304b\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u6bce\u56de\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u4f5c\u6210\u3059\u308b\u306e\u306f\u5c11\u3057\u3081\u3093\u3069\u304f\u3055\u3044\u3067\u3059\u3088\u306d\u3002\u305d\u306e\u305f\u3081\u306bJava\u3067\u306f\u3001\u300cjava.util.function\u300d\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u3057\u3066\u6c4e\u7528\u7684\u306aSAM\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<table>\n<tbody>\n<tr>\n<th>\u540d\u524d<\/th>\n<th>\u5f15\u6570<\/th>\n<th>\u623b\u308a\u5024<\/th>\n<th>\u30e1\u30bd\u30c3\u30c9\u540d<\/th>\n<\/tr>\n<tr>\n<td>IntBinaryOperator<\/td>\n<td>int,int<\/td>\n<td>int<\/td>\n<td>applyAsInt<\/td>\n<\/tr>\n<tr>\n<td>IntToLongFunction<\/td>\n<td>int<\/td>\n<td>long<\/td>\n<td>applyAsLong<\/td>\n<\/tr>\n<tr>\n<td>IntToDoubleFunction<\/td>\n<td>int<\/td>\n<td>double<\/td>\n<td>applyAsDouble<\/td>\n<\/tr>\n<tr>\n<td>IntConsumer<\/td>\n<td>int<\/td>\n<td>\u306a\u3057<\/td>\n<td>accept<\/td>\n<\/tr>\n<tr>\n<td>IntSupplier<\/td>\n<td>\u306a\u3057<\/td>\n<td>int<\/td>\n<td>getAsInt<\/td>\n<\/tr>\n<tr>\n<td>IntPredicate<\/td>\n<td>int<\/td>\n<td>boolean<\/td>\n<td>test<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"\u3053\u3053\u3067\u6271\u3046\u6982\u5ff5\u306f\u3001\u5c11\u3057\u96e3\u89e3\u306a\u6982\u5ff5\u306a\u306e\u3067\u3001\u3042\u305b\u3063\u3066\u7406\u89e3\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002Java\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306b\u306a\u308c\u3066\u3044\u306a\u3044\u65b9\u306f\u3001\u307e\u305a\u306fJava7\u307e\u3067\u306e\u57fa\u672c\u69cb\u6587\u3060\u3063\u305f\u308a\u3001\u696d\u52d9\u3067\u4f7f\u3063\u3066\u3044\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3084\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u77e5\u8b58\u304b\u3089\u5148\u306b\u5b66\u7fd2\u3055\u308c [&hellip;]","protected":false},"author":1,"featured_media":491,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2129"}],"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=2129"}],"version-history":[{"count":15,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2129\/revisions"}],"predecessor-version":[{"id":20242,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2129\/revisions\/20242"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/491"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2129"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}