
{"id":2132,"date":"2020-08-19T15:25:11","date_gmt":"2020-08-19T07:25:11","guid":{"rendered":"http:\/\/127.0.0.2\/?p=2132"},"modified":"2020-08-23T10:05:17","modified_gmt":"2020-08-23T02:05:17","slug":"2020java%e6%95%99%e7%a8%8b%ef%bc%9a%e5%8c%85%e8%a3%85%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2132","title":{"rendered":"2020java\u6559\u7a0b\uff1a\u5305\u88c5\u7c7b"},"content":{"rendered":"<h3>\u5305\u88c5\u7c7b<\/h3>\n<p>\u4ec0\u4e48\u662f\u5305\u88c5\u7c7b\uff1f<br \/>\n\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6240\u5bf9\u5e94\u7684\u5f15\u7528\u6570\u636e\u7c7b\u578b\u3002<br \/>\nObject\u53ef\u7edf\u4e00\u6240\u6709\u6570\u636e\uff0c\u5305\u88c5\u7c7b\u7684\u9ed8\u8ba4\u503c\u662fnull<\/p>\n<pre>public class demos{\r\n    public static void main(String[] args) {\r\n        Byte b1=new Byte(10);\r\n        System.out.println(b1);\r\n    }\r\n}<!--more-->\r\n\r\n\r\nclass Byte{\r\n    byte value;\r\n    public Byte(byte value) {\r\n        this.value = value;\r\n    }\r\n    public Byte(int value) {\r\n        this.value = (byte)value;\r\n    }\r\n    @Override\r\n    public String toString(){\r\n        return this.value+\"\";\r\n    }\r\n}<\/pre>\n<p>\u5305\u88c5\u7c7b\u5bf9\u5e94<\/p>\n<pre>\u57fa\u672c\u6570\u636e\u7c7b\u578b      \u5305\u88c5\u7c7b\u578b\r\nbyte               Byte\r\nshort           Short\r\nint             Integer\r\nlong             Long\r\nfloat           Float\r\ndouble          Double\r\nboolean         Boolean\r\nchar            Character<\/pre>\n<p>\u7c7b\u578b\u8f6c\u6362\u4e0e\u88c5\u7bb1\u3001\u62c6\u7bb1<br \/>\n8\u4e2a\u5305\u88c5\u7c7b\u63d0\u4f9b\u4e0d\u540c\u7c7b\u578b\u7684\u8f6c\u6362<\/p>\n<pre>\/\/\u5c06\u5305\u88c5\u7c7b\u578b\u8f6c\u6362\u4e3a\u57fa\u672c\u7c7b\u578b\r\nShort s=new Short(\"10\");\r\nbyte b1=s.byteValue();\r\nshort s2=s.shortValue();\r\nint i=s.intValue();\r\nlong l=s.longValue();\r\ndouble d=s.doubleValue();\r\nfloat f=s.floatValue();<\/pre>\n<p>parseXXX()\u9759\u6001\u65b9\u6cd5<\/p>\n<pre>\/\/\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210byte\r\nbyte b=Byte.parseByte(\"123\");\r\nbyte b2=new Byte(\"123\").byteValue();<\/pre>\n<p>valueOf()\u9759\u6001\u65b9\u6cd5<\/p>\n<pre>\/\/valueOf()\r\nByte b3=Byte.valueOf((byte)123);\r\n\/\/ERROR java.util.lang.NumberFormatException\u5f02\u5e38\r\nByte b4=new Byte(\"1a2b3c\");<\/pre>\n<p>\u6ce8\u610f\uff1a\u9700\u4fdd\u8bc1\u7c7b\u578b\u517c\u5bb9\uff0c\u5426\u5219\u629b\u51fajava.util.lang.NumberFormatException\u5f02\u5e38<\/p>\n<p>JDK5.0\u4e4b\u540e\uff0c\u81ea\u52a8\u88c5\u7bb1\u3001\u62c6\u7bb1\u3002\u57fa\u672c\u6570\u636e\u7c7b\u578b\u548c\u5305\u88c5\u7c7b\u81ea\u52a8\u8f6c\u6362<\/p>\n<p>\u6574\u6570\u7f13\u51b2\u533a<br \/>\njava\u9884\u5148\u521b\u5efa\u4e86256\u4e2a\u5e38\u7528\u7684\u6574\u6570\u5305\u88c5\u7c7b\u578b\u5bf9\u8c61<br \/>\n\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5bf9\u5df2\u521b\u5efa\u7684\u5bf9\u8c61\u8fdb\u884c\u590d\u7528<\/p>\n<p>short\u7f13\u5b58\u533a<br \/>\nstatic final Short cache[] =new Short[-(-128)+127+1];\/\/256<\/p>\n<pre>static {\r\n    for(int i=0;i&lt;cache.length;i++){\r\n        cache[i]=new Short((short)(i-128));\r\n    }\r\n}<\/pre>\n<pre>public static Short valueOf(short s) {\r\n    final int offset = 128;\r\n    int sAsInt = s;\r\n    if (sAsInt &gt;= -128 &amp;&amp; sAsInt &lt;= 127) { \/\/ must cache\r\n        return ShortCache.cache[sAsInt + offset];\r\n    }\r\n    return new Short(s);\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5305\u88c5\u7c7b \u4ec0\u4e48\u662f\u5305\u88c5\u7c7b\uff1f \u57fa\u672c\u6570\u636e\u7c7b\u578b\u6240\u5bf9\u5e94\u7684\u5f15\u7528\u6570\u636e\u7c7b\u578b\u3002 Object\u53ef\u7edf\u4e00\u6240\u6709\u6570\u636e\uff0c\u5305\u88c5\u7c7b\u7684\u9ed8\u8ba4\u503c\u662fnul [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2132","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2132"}],"version-history":[{"count":5,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2132\/revisions"}],"predecessor-version":[{"id":2157,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2132\/revisions\/2157"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}