锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲av中文无码乱人伦在线播放 ,亚洲精品国产电影午夜,亚洲欧美自偷自拍另类视http://m.tkk7.com/cisco/category/6318.htmlJava, 涓鏉祿嫻撶殑鍜栧暋浼翠綘鍒版繁澶?lt;br> <span id="dict_daily"> <a target="_blank">Dict.CN 鍦ㄧ嚎璇嶅吀, 鑻辮瀛︿範, 鍦ㄧ嚎緲昏瘧</a> </span> <script language="JavaScript" src="http://dict.cn/daily.php" defer="defer"> </script>zh-cnWed, 28 Feb 2007 13:00:41 GMTWed, 28 Feb 2007 13:00:41 GMT60銆奐ava 5.0 Tiger銆婥hapter 4http://m.tkk7.com/cisco/articles/26211.htmlScott@JAVAScott@JAVASat, 31 Dec 2005 15:17:00 GMThttp://m.tkk7.com/cisco/articles/26211.htmlhttp://m.tkk7.com/cisco/comments/26211.htmlhttp://m.tkk7.com/cisco/articles/26211.html#Feedback0http://m.tkk7.com/cisco/comments/commentRss/26211.htmlhttp://m.tkk7.com/cisco/services/trackbacks/26211.htmlChapter 4. Autoboxing and Unboxing

4.1 Converting Primitives to Wrapper Types

Integer i = 0;

Behind the scenes, primitive values are boxed. Boxing refers to the conversion from a primitive to its corresponding wrapper type: Boolean, Byte, Short, Character, Integer, Long, Float, or Double. Because this happens automatically, it's generally referred to as autoboxing.

It's also common for Java to perform a widening conversion in addition to boxing a value:

Number n = 0.0f;

Here, the literal is boxed into a Float, and then widened into a Number.

Additionally, the Java specification indicates that certain primitives are always to be boxed into the same immutable wrapper objects. These objects are then cached and reused, with the expectation that these are commonly used objects. These special values are the boolean values true and false, all byte values, short and int values between -128 and 127, and any char in the range \u0000 to \u007F.

4.2 Coverting Wrapper Types to Primitives

// Boxing
int foo = 0;
Integer integer 
= foo;

// Simple Unboxing
int bar = integer;

Integer counter 
= 1;     // boxing
int counter2 = counter;  // unboxing

...null value assignment? Since null is a legal value for an object, and therefore any wrapper type, the following code is legal:

Integer i = null;
int j = i; 

i is assigned null (which is legal), and then i is unboxed into j. However, null isn't a legal value for a primitive, so this code throws a NullPointerException.

4.3 Incrementing and Decrementing Wrapper Types

Suddenly, every operation available to a primitive should be available to its wrapper-type counterpart, and vice versa.

Integer counter = 1;
        
while (true{
            System.out.printf(
"Iteration %d%n", counter++);
            
if (counter > 1000)
                
break;
        }

Remember that counter is an Integer. So the value in counter was first auto-unboxed into an int, as that's the type required for the ++ operator. Once the value is unboxed, it is incremented. Then, the new value has to be stored back in counter, which requires a boxing operation. All this in a fraction of a second!

4.4 Boolean Versus boolean

Any time you have an expression that uses !, ||, or &&, any Boolean values are unboxed to boolean primitive values, and evaluated accordingly:

        Boolean case1 = true;
        Boolean case2 
= true;
        
boolean case3 = false;
        Boolean result 
= (case1 || case2) && case3;

For inquiring minds, primitives are boxed up to wrapper types in equality comparisons. For operators such as <, >=, and so forth, the wrapper types are unboxed to primitive types.

Atten! ...direct object comparison?

You can't depend on the result; it's merely used as an illustration. Some JVMs may choose to try and optimize this code, and create one instance for both Integer objects, and in that case, the == operator would return a true result.

        Integer i1 = 256;
        Integer i2 
= 256;
        Integer i3 
= 100;
        Integer i4 
= 100;
        System.out.println(i1 
== i2); // false
        System.out.println(i3 == i4); // true

If you wonder the result above, check the last paragraph in 4.1 Converting Primitives to Wrapper Types.

4.5 Conditionals and Unboxing

Ternary operator --- [conditional expression] ? [expression1] : [expression2]

[expression1] and [expression2] had to either be of the same type, or one had to be assignable to the other.


Another addition to Tiger is automatic casting of reference to their intersection type. That's a mouthful, so here's an example:

        String s = "hello";
        StringBuffer sb 
= new StringBuffer("world");
        
boolean mutable = true;
        CharSequence cs 
= mutable ? sb : s;

In pre-Tiger environments, this would generate an error, as sb (a StringBuffer) and s (a String) cannot be assigned to each other, unless you explicitly cast both to CharSequence.

As a side effect of this, note that two reference types (objects) always share java.lang.Object as a common ancestor, so any result of a ternary operation involving non-primitive operands can be assigned to java.lang.Object.

4.6 Control Statements and Unboxing

if/else, while, and do all are affected by Tiger's ability to unbox Boolean values to boolean values.

Another statement that benefits from unboxing is switch. In pre-Tiger JVMs, the switch statement accepts int, short, char, or byte values. With unboxing in play, you can now supply it with Integer, Short, Char, and Byte values as well, in addition to the introduction of enums.

4.7 Method Overload Resolution

In Tiger, method resolution is a three-pass process:

  1. The compiler attempts to locate the correct method without any boxing, unboxing, or vararg invocations. This will find any method that would have been invoked under Java 1.4 rules.

  2. If the first pass fails, the compiler tries method resolution again, this time allowing boxing and unboxing conversions. Methods with varargs are not considered in this pass.

  3. If the second pass fails, the compiler tries method resolution one last time, allowing boxing and unboxing, and also considers vararg methods.

These rules ensure that consistency with pre-Tiger environments is maintained.



Scott@JAVA 2005-12-31 23:17 鍙戣〃璇勮
]]>
銆奐ava 5.0 Tiger銆婥hapter 3http://m.tkk7.com/cisco/articles/25975.htmlScott@JAVAScott@JAVAThu, 29 Dec 2005 21:28:00 GMThttp://m.tkk7.com/cisco/articles/25975.htmlhttp://m.tkk7.com/cisco/comments/25975.htmlhttp://m.tkk7.com/cisco/articles/25975.html#Feedback0http://m.tkk7.com/cisco/comments/commentRss/25975.htmlhttp://m.tkk7.com/cisco/services/trackbacks/25975.html闃呰鍏ㄦ枃

Scott@JAVA 2005-12-30 05:28 鍙戣〃璇勮
]]>
銆奐ava 5.0 Tiger銆婥hapter 2http://m.tkk7.com/cisco/articles/25522.htmlScott@JAVAScott@JAVAMon, 26 Dec 2005 19:30:00 GMThttp://m.tkk7.com/cisco/articles/25522.htmlhttp://m.tkk7.com/cisco/comments/25522.htmlhttp://m.tkk7.com/cisco/articles/25522.html#Feedback0http://m.tkk7.com/cisco/comments/commentRss/25522.htmlhttp://m.tkk7.com/cisco/services/trackbacks/25522.html闃呰鍏ㄦ枃

Scott@JAVA 2005-12-27 03:30 鍙戣〃璇勮
]]>
銆奐ava 5.0 Tiger銆婥hapter 1http://m.tkk7.com/cisco/articles/25387.htmlScott@JAVAScott@JAVASun, 25 Dec 2005 14:24:00 GMThttp://m.tkk7.com/cisco/articles/25387.htmlhttp://m.tkk7.com/cisco/comments/25387.htmlhttp://m.tkk7.com/cisco/articles/25387.html#Feedback0http://m.tkk7.com/cisco/comments/commentRss/25387.htmlhttp://m.tkk7.com/cisco/services/trackbacks/25387.html闃呰鍏ㄦ枃

Scott@JAVA 2005-12-25 22:24 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 亚洲av日韩av激情亚洲| 一区国严二区亚洲三区| 亚洲av色福利天堂| 中文字幕版免费电影网站| 亚洲精品亚洲人成在线观看下载| 国产91成人精品亚洲精品| 免费午夜爽爽爽WWW视频十八禁 | 91视频免费网址| 亚洲av永久无码精品表情包| 三年在线观看免费观看完整版中文 | 精品亚洲A∨无码一区二区三区| 免费观看在线禁片| 亚洲一卡2卡三卡4卡有限公司| 2019中文字幕免费电影在线播放| 亚洲成AV人片久久| 日韩电影免费在线| 男人扒开添女人下部免费视频| 中文字幕在亚洲第一在线| 免费无码又爽又刺激网站直播| 亚洲综合国产精品| 国产一卡2卡3卡4卡2021免费观看| 亚洲熟女www一区二区三区| 国产免费怕怕免费视频观看| 午夜不卡AV免费| 亚洲av日韩av无码黑人| ww在线观视频免费观看| 亚洲精品无播放器在线播放| 国产又大又黑又粗免费视频 | 久久久亚洲欧洲日产国码aⅴ| 美女网站免费福利视频| 在线精品自拍亚洲第一区| 亚洲午夜久久久影院| 亚洲视频免费观看| 色综合久久精品亚洲国产| 国产成人亚洲综合无码精品| 青苹果乐园免费高清在线| ssswww日本免费网站片| 亚洲理论在线观看| 亚洲国产黄在线观看| 色欲色香天天天综合网站免费| 亚洲精品美女久久7777777|