This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
It compiled run fine here. Can you paste some errors what compiler is complaining about?
SCJP 5.0, SCJD URLyBird 1.3.3, OCMJEA 5 (SCEA) Factory Homes
Joined: Nov 25, 2007
I hace checked the version and its java 1.5 Also the installation folder says its 1.5 Additionally i have tried 2 compile it with the command:
javac -source 1.5 #filename.java
And its working fine in my friends compiler. As requested here are the errors i got:
Please help. Thanks.
Kelvin Chenhao Lim
Joined: Oct 20, 2007
Interesting. This looks like it might be a compiler bug. Perhaps you may want to try updating to the latest Sun JDK 5 distribution, or try a different version if you're already using the latest version.
Hi, I tried the same code, its working fine on my pc.
But I have another question regarding this. With reference to line#5, it states in the book that(taken from pg 564 bottom para):
Why didn't we find the Cat key String? Why did it work to use an instance of Dog as a key, when using an instance of Cat as a key failed? It's easy to see that Dog overrode equals() and hashCode() while Cat didn't.
1) I tried commenting the equals() and hashCode() used in Dog class, but the code runs and produces the same output. 2) If this code set is used:
instead of this one given in the book:
it produces the expected output (Cat key).
So, I feel with regards to 1) and 2), its really not a MUST for a class to override the equals() and hashCode() for using as apart of the key. Please comment and explain why this behaviour?
Notice how whenever the error messages talk about String, they say java.lang.String. But when they talk about Object, they just say Object. The should give the fully qualified name, java.lang.Object. The fact that they don't suggests that you have done something extremely evil, and created your own class called Object (with no package). Delete the files Object.java and Object.class from your classpath, and never, ever do this again, as it only leads to confusion.
"I'm not back." - Bill Harding, Twister
Joined: Nov 25, 2007
I tried installing java 5.0 again without any success at the code. It still doesnt get compiled and am getting those 7 errors i mentioned earlier. Kindly guide on how to proceed.