| Author |
Key Class for Products
|
Pradeep Shankar
Greenhorn
Joined: Apr 23, 2011
Posts: 3
|
|
How can I change this class so that it is suitable for use as a key in a collection.
All three fields (serialNumber, productName and price) are required to uniquely identify a product.
Instances of this class will be utilized as key values in a JNDI lookup operation
Thank you for taking the time to read this...
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
By "key", I am assuming you want this in a map.... well, then, the answer is "it depends".
If you want it in a hashing map, then you need to implement the equals() and hashCode() method. And if you want it in a treemap, then you either need to make your instance implement Comparable, or write a Comparator class for it.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
. . . and it ought to be immutable, if you ever want to find it again
|
 |
Pradeep Shankar
Greenhorn
Joined: Apr 23, 2011
Posts: 3
|
|
Thanks guys...
Requirements:
This interface should be used to retrieve details regarding an payment. A JNDI lookup will result in a suitable implementation being returned (assume that it is bound to the JNDI_NAME supplied below). The interface has been simplified to exclude and remote method invocation concepts.
Interface for retrieving details of an payment:
So it can be used in the front end app, see:
Bind Class to HttpSession Posting
Would appreciate it if someone could help me.
|
 |
 |
|
|
subject: Key Class for Products
|
|
|