• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

List example

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Dick Summerfield
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Quick! Before anybody notices! Cover it up with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic