JavaRanch » Java Forums »
Java »
Beginning Java
| Author |
List example
|
Dick Summerfield
Ranch Hand
Joined: Oct 04, 2007
Posts: 90
|
|
Hi all, Here's the code for a List example taken from Just Java 2 Fifth Edition (that's the one that handles JDK 1.4 release) p. 460: The author says: "we write an interface that has constants for the suit and rank of each card ... a class that holds four cards, inherits these constants by implementing the interface. The example works fine and I've learnt a lot about Collections from expanding this example, but what's the point of that interface. If I delete the whole goldurn thing the program works just as well!!! Can somebody please explain this? I'm sure I must be missing something... [ January 20, 2008: Message edited by: Dick Summerfield ]
|
 |
Paul Santa Maria
Ranch Hand
Joined: Feb 24, 2004
Posts: 236
|
|
Hi - No, you're not missing anything. On pg 460, Mr. van der Linden says:
"[class 'Hand'] .. inherits these constants by implementing the interface."
But then he never bothers using any of the constants he went to the trouble of inheriting - he just declares some new constants, in String[] "example". Great book; poor example. 'Hope that helps .. PSM
|
Paul M. Santa Maria, SCJP
|
 |
Dick Summerfield
Ranch Hand
Joined: Oct 04, 2007
Posts: 90
|
|
Originally posted by Paul Santa Maria: No, you're not missing anything. ... he never bothers using any of the constants he went to the trouble of inheriting - Great book; poor example. 'Hope that helps .. PSM
It certainly did, Paul - Thanks I changed the code as follows: ... which I think illustrates the point, though I'd want to make it more readable somehow for everyday use  [ January 20, 2008: Message edited by: Dick Summerfield ]
|
 |
 |
|
|
subject: List example
|
|
|
|