YUE ZHU

Greenhorn
+ Follow
since Nov 17, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by YUE ZHU

Hi Ranchers,

Passed,thank for all your helps!

Best,
Yue Zhu
10 years ago
11.
D. It is appropriate to use assertions to generate alerts when you reach code that should not be reachable.

The point is unreachable code can not even compile, how can use assert at that situation?



compile fail: unreachable code

Best,
Yue
Hi David,
I looked at the link you provided, but don't found any override words.

I do know follow the Serializable contract, but I just don't buying
that is an override method.

Best,
Yue
Hi Bert,

K&B book, Page 507, #15 the answer is C,F.
I am wondering the statement F is true or not:

F. In order to alter the standard deserialization process you would override the readObject() method in SpecialSerial.

The readObject() method signature would be:


I think the statement violate the override rules:
1.There is no super class have this method, no in Serializable
2.private method not inherit, so can't be override
3.override method can't have less accessable

Best,
Yue
Bug of Java Compiler? :-)

Anyone help?

Best,
Yue
I run this fine,and outputs:
long


but,when I add a parameter more, it's go wrong:

It shows ambiguous, I don't know why? Anyone help?

Best,
Yue
Hi Anthony,
You may write the code in wrong way, the return type is Object[], so you need to explicitly cast. The list1.toArray(T[]) use the parameter as the array to store or use it as Type info to generate new array.
so the code should be:


And array in Java is fixed size, size 0 is a size.

Best,
Yue
Generics type is about the erasure and cast, so if you mix use the generic and non-generic will compile but will throw RuntimeException.

Rule: generic is compiler magic,it simply erase the type and cast it.

Look at the source code I decompiled from the TestMap:

You see? it Cast the Integer to String, that's why throw ClassCastException.

Best,
Yue
This program runs well and prints:
11

If you want it Throw ClassCastException, you need to change

to:



Best,
Yue
Then I have some question about K&B book at Page235:

should be:

I think the static method must be invoked to gain boxing effect,since it's fast and no need to instance a new object if x2 within -128 to 127.

Best,
Yue
Thank you Aniket. Your explanation is clear.

Best,
Yue
K&B p240:compiler choose old style before it choose new one,
but this get me confusing,how about this output?

public class Confusing {
     private Confusing(Object o) {
         System.out.println("Object");
     }

// private Confusing(double[] dArray) {
// System.out.println("double array");
// }
     private Confusing(double...ds ){
         System.out.println("double ...");
     }

     public static void main(String[] args) {
         new Confusing(null);
     }
}

old beat vararg? No.
//output
double ...

Somebody help!

Best,
Yue

[ December 28, 2006: Message edited by: YUE ZHU ]

[ December 28, 2006: Message edited by: YUE ZHU ]
[ January 10, 2007: Message edited by: YUE ZHU ]
Hi Dave,
Your notes is great, save me a lot of time. Thanks a lot in advance.

I found that new Integer(120) == new Integer(120) is false. Maybe you can update your notes a little bit. :-)
//source
class IntegerCompare {

public static void main(String[] args) {
Integer i = 120;
Integer j = 120;
System.out.println(i == j);
Integer k = new Integer(120);
Integer l = new Integer(120);
System.out.println(k == l);
//or
System.out.println(new Integer(120) == new Integer(120));
}
}
//output
true
false
false

I think only the Integer variable assigned with int literal in range -128 to 127 are true when compare with "==". Maybe just like String.intern()
sth Integer constant pool. :-)

Best,
Yue