﻿{"id":1019,"date":"2013-05-29T10:44:52","date_gmt":"2013-05-29T01:44:52","guid":{"rendered":"http:\/\/yucchi.jp\/blog\/?p=1019"},"modified":"2013-05-29T10:46:00","modified_gmt":"2013-05-29T01:46:00","slug":"%e3%82%82%e3%81%a3%e3%81%a8-lambda-%e3%81%9d%e3%81%ae%ef%bc%91%ef%bc%92","status":"publish","type":"post","link":"http:\/\/yucchi.jp\/blog\/?p=1019","title":{"rendered":"\u3082\u3063\u3068 Lambda \u305d\u306e\uff11\uff12"},"content":{"rendered":"<p>\u6628\u65e5\u306e Java \u30d1\u30ba\u30e9\u30fc\u306e\u8d85\u30a6\u30eb\u30c8\u30e9\u30d2\u30f3\u30c8\u3092\u30fb\u30fb\u30fb<\/p>\n<p>\u305f\u3076\u3093\u3001\u5fc5\u8981\u306a\u3044\u3068\u601d\u3046\u3051\u3069\u30fb\u30fb\u30fb<\/p>\n<pre title=\"Infinity.java\">\r\npackage jp.yucchi.infinity;\r\n\r\nimport java.util.stream.IntStream;\r\n\r\npublic class Infinity {\r\n\r\n    public static void main(String[] args) {\r\n\r\n        IntStream.range(Integer.MAX_VALUE - 3, Integer.MAX_VALUE, 2).limit(5).forEach(System.out::println);\r\n\r\n        System.out.println(\"***********************************\");\r\n        \r\n        int count = 0;\r\n        for (int i = 0; i <= Integer.MAX_VALUE; Math.addExact(0, i++)) {\r\n            count++;\r\n            if (i > Integer.MAX_VALUE - 5) {\r\n                System.out.println(i);\r\n            }\r\n        }\r\n        System.out.println(count);\r\n    }\r\n\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\u3053\u306e\u30d1\u30ba\u30eb\u306f\u53e4\u5178\u7684\u306a\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u3092\u3068\u308a\u3042\u3052\u3066\u307e\u3059\u3002<\/p>\n<pre>IntStream.range(Integer.MAX_VALUE - 3, Integer.MAX_VALUE, 2)<\/pre>\n<p>\u3053\u306e\u65b0\u3057\u3044\u69cb\u6587\u306f\u3001<\/p>\n<pre>for (int i = startInclusive; i &lt; endExclusive ; i += step) { ... }<\/pre>\n<p>\u3068\u540c\u3058\u3067\u3001i += step \u306e\u3068\u3053\u308d\u3067\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u3092\u304a\u3053\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre>for (int i = 0; i &lt;= Integer.MAX_VALUE; Math.addExact(0, i++)) { ... }<\/pre>\n<p>\u3053\u306e\u30eb\u30fc\u30d7\u6587\u306f\u4e00\u898b\u3059\u308b\u3068 Math.addExact() \u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u306e\u3067\u4f8b\u5916\u304c\u51fa\u308b\u3068\u601d\u3063\u3066\u3057\u307e\u3044\u304c\u3061\u3067\u3059\u304c\u3001<\/p>\n<p>\u3088\uff5e\uff5e\uff5e\u304f\u898b\u308b\u3068\u5f15\u6570\u306e i++ \u3067\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u3059\u308b\u306e\u3067\u7121\u9650\u30eb\u30fc\u30d7\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u3068\u3066\u3082\u53e4\u5178\u7684\u3067\u7c21\u5358\u306a\u30d1\u30ba\u30eb\u3067\u3057\u305f\u3002<\/p>\n<p>\u3053\u308c\u3060\u3051\u3060\u3068\u5bc2\u3057\u3044\u306e\u3067 Math.addExact() \u30e1\u30bd\u30c3\u30c9\u3092\u8997\u3044\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre>    public static int addExact(int x, int y) {\r\n        int r = x + y;\r\n        \/\/ HD 2-12 Overflow iff both arguments have the opposite sign of the result\r\n        if (((x ^ r) &amp; (y ^ r)) &lt; 0) {\r\n            throw new ArithmeticException(\"integer overflow\");\r\n        }\r\n        return r;\r\n    }<\/pre>\n<p>\u306a\u3093\u304b\u826f\u304f\u89e3\u3089\u306a\u3044\u3051\u3069\u30d3\u30c3\u30c8\u6f14\u7b97\u3092\u99c6\u4f7f\u3057\u3066\u5224\u5b9a\u3057\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u306d\u3002<\/p>\n<p>\u306a\u3093\u3067\u4eca\u9803\u3053\u3093\u306a\u3082\u306e\u3092\u30fb\u30fb\u30fb\u4ee5\u4e0b\u81ea\u7c9b\u3002(^_^;)<\/p>\n<div class=\"wlWriterEditableSmartContent\" id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d01e11c1-3519-4344-aa77-d76a88563cf7\" style=\"margin: 0px; padding: 0px; float: none; display: inline;\">Hatena \u30bf\u30b0: <a href=\"http:\/\/b.hatena.ne.jp\/t\/Java\" rel=\"tag\">Java<\/a><\/div>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_hatena\"><a href='\/\/b.hatena.ne.jp\/add?mode=confirm&url=http%3A%2F%2Fyucchi.jp%2Fblog%2F%3Fp%3D1019&title=%E3%82%82%E3%81%A3%E3%81%A8%20Lambda%20%E3%81%9D%E3%81%AE%EF%BC%91%EF%BC%92' title='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='http:\/\/yucchi.jp\/blog\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/hatena.gif' alt='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' title='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' width='16' height='12' class='wp_social_bookmarking_light_img' \/><\/a><\/div>\n            <div class=\"wsbl_facebook\"><a href='http:\/\/www.facebook.com\/share.php?u=http%3A%2F%2Fyucchi.jp%2Fblog%2F%3Fp%3D1019&t=%E3%82%82%E3%81%A3%E3%81%A8%20Lambda%20%E3%81%9D%E3%81%AE%EF%BC%91%EF%BC%92' title='Facebook \u306b\u30b7\u30a7\u30a2' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='http:\/\/yucchi.jp\/blog\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/facebook.png' alt='Facebook \u306b\u30b7\u30a7\u30a2' title='Facebook \u306b\u30b7\u30a7\u30a2' width='16' height='16' class='wp_social_bookmarking_light_img' \/><\/a><\/div>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"http:\/\/yucchi.jp\/blog\/?p=1019\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"http:\/\/yucchi.jp\/blog\/?p=1019\" data-text=\"\u3082\u3063\u3068 Lambda \u305d\u306e\uff11\uff12\" data-lang=\"ja\">Tweet<\/a><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>\u6628\u65e5\u306e Java \u30d1\u30ba\u30e9\u30fc\u306e\u8d85\u30a6\u30eb\u30c8\u30e9\u30d2\u30f3\u30c8\u3092\u30fb\u30fb\u30fb \u305f\u3076\u3093\u3001\u5fc5\u8981\u306a\u3044\u3068\u601d\u3046\u3051\u3069\u30fb\u30fb\u30fb package jp.yucchi.infinity; import java.util.stream.IntStream; public class Infinity { public static void main(String[] args) { IntStream.range(Integer.MAX_VALUE &#8211; 3, Integer.MAX_VALUE, 2).limit(5).forEach(System.out::println); System.out.println(&#8220;********\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[17],"class_list":["post-1019","post","type-post","status-publish","format-standard","hentry","category-java","tag-java"],"_links":{"self":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1019","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1019"}],"version-history":[{"count":8,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1019\/revisions"}],"predecessor-version":[{"id":1027,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1019\/revisions\/1027"}],"wp:attachment":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1019"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1019"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}