{"id":2234,"date":"2023-05-07T06:31:55","date_gmt":"2023-05-06T22:31:55","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2234"},"modified":"2023-05-07T09:56:43","modified_gmt":"2023-05-07T01:56:43","slug":"groovy-code-example-variable-type-conversion","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/05\/07\/groovy-code-example-variable-type-conversion\/","title":{"rendered":"Groovy\u4ee3\u7801\u793a\u4f8b &#8211; \u53d8\u91cfvariable\u53ca\u7c7b\u578b\u8f6c\u6362"},"content":{"rendered":"<h2>\u53d8\u91cfvariable<\/h2>\n<p>groovy\u4e2d\u7684\u53d8\u91cf\u7c7b\u578b\u4e0d\u662f\u5fc5\u987b\u7684\uff0c\u53ef\u4ee5\u662f\u65e0\u7c7b\u578b\u7684\u3002\u4f8b\u5982\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-java\">int x = 1\nint y = 2\nassert x+y == 3<\/code><\/pre>\n<p>\u8ddf\u4e0b\u9762\u7684\u4ee3\u7801\u662f\u7b49\u4ef7\u7684\uff1a<\/p>\n<pre><code class=\"language-java\">x = 1\ny = 2\nassert x+y == 3<\/code><\/pre>\n<p>\u4f46\u662f\u4e24\u79cd\u8fd8\u662f\u6709\u4e00\u4e9b\u7ec6\u5fae\u5dee\u522b\u7684\uff1a<\/p>\n<ul>\n<li>1\uff09\u5982\u679c\u53d8\u91cf\u50cf\u7b2c\u4e00\u79cd\u65b9\u5f0f\u90a3\u6837\u53bb\u5b9a\u4e49\uff0c\u53d8\u91cf\u662f\u5c40\u90e8\u53d8\u91cf\u3002\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u4ec5\u4ec5\u9650\u4e8erun\u65b9\u6cd5\u5185\u90e8\uff0c\u6362\u53e5\u8bdd\u8bf4\uff1a\u5c40\u90e8\u53d8\u91cf\u4e0d\u80fd\u88ab\u5176\u4ed6\u65b9\u6cd5\u6240\u80fd\u8bbf\u95ee<\/li>\n<li>2\uff09\u5982\u679c\u53d8\u91cf\u672a\u5b9a\u4e49\uff0c\u5c31\u4f1a\u8bbf\u95ee\u811a\u672c\u7ed1\u5b9a\u7684\u53d8\u91cf\u3002\u7ed1\u5b9a\u7684\u53d8\u91cf\u65b9\u6cd5\u91cc\u662f\u53ef\u89c1\u7684\uff0c\u7ed1\u5b9a\u53d8\u91cf\u5728\u811a\u672c\u9700\u8981\u4e0e\u5916\u90e8\u7a0b\u5e8f\u4ea4\u4e92\u65f6\u7279\u522b\u6709\u7528<\/li>\n<\/ul>\n<h2>groovy\u4e2d\u5982\u4f55\u5c06\u5b57\u7b26\u4e32\u8f6c\u4e3a\u6574\u5f62\u6570\u5b57\uff1f<\/h2>\n<p>\u65b9\u6cd51:<\/p>\n<pre><code class=\"language-java\">int value = &quot;99&quot;.toInteger()<\/code><\/pre>\n<p>\u65b9\u6cd52:<\/p>\n<pre><code class=\"language-java\">int value = &quot;66&quot; as Integer<\/code><\/pre>\n<p>\u5982\u679c\u9700\u8981\u5bf9\u5b57\u7b26\u4e32\u68c0\u67e5\u7684\u8bdd\uff0c\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/p>\n<pre><code class=\"language-java\">String number = &quot;66&quot;\n\nif (number.isInteger()) { \/\/\u68c0\u67e5\u662f\u5426\u4e3a\u6574\u6570\n  int value = number as Integer\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53d8\u91cfvariable groovy\u4e2d\u7684\u53d8\u91cf\u7c7b\u578b\u4e0d\u662f\u5fc5\u987b\u7684\uff0c\u53ef\u4ee5\u662f\u65e0\u7c7b\u578b\u7684\u3002\u4f8b\u5982\u4ee5\u4e0b\u4ee3\u7801\uff1a int x = 1  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[568],"tags":[],"class_list":["post-2234","post","type-post","status-publish","format-standard","hentry","category-groovy"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2234"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2234\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}