Rob Sanheim

Greenhorn
+ Follow
since Nov 02, 2004
Merit badge: grant badges
For More
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 Rob Sanheim

This is a pretty old thread, but I'm going to revive it because I've been researching this very topic today. Bloch comments on the debate between using instaceof and getClass() here:

http://www.codeproject.com/useritems/EmailWithJoshuaBloch.asp

The link is to a fairly lengthy email Block wrote to someone who wrote to him asking about the same thing...If you don't want to read the whole thing, here's the main idea of Bloch's arguement:

This technique ("getClass-based equals methods") does satisfy the equals
contract, but at great cost. The disadvantage of the getClass approach
is that it violates the "Liskov Substitution Principle," which states
(roughly speaking) that a method expecting a superclass instance must
behave properly when presented with a subclass instance. If a subclass
adds a few new methods, or trivially modifies behavior (e.g., by
emitting a trace upon each method invocation), programmers will be
surprised when subclass and superclass instances don't interact
properly. Objects that "ought to be equal" won't be, causing programs
to fail or behave erratically. The problem is exacerbated by the fact
that Java's collections are based on the equals method.

Look into _Head First Servlets and JSP_.

Its a great book, and will prep you for the web component exam, also.

http://www.amazon.com/exec/obidos/tg/detail/-/0596005407/002-0236176-8482400?v=glance
[ November 02, 2004: Message edited by: Rob Sanheim ]
19 years ago