0

I have a hashtable with contains the a unique identifier as the key and an object as the value. I'm trying to go through all the values in the hashtable and print out the object's values, but Eclipse is telling me that the object's members cannot be resolved. My code looks like this:

Enumeration<myobj> items = myhashtable.elements(); while (items.hasMoreElements()) { System.out.println(items.X + " - " + items.Y.Z()); items.nextElement(); } 

X is a String and Y is another object within the main object, its method Z returns a string.

1
  • What is the exact error message...? Commented Sep 7, 2014 at 3:42

1 Answer 1

2

You are calling your fields on the wrong object.

Enumeration<myobj> items = myhashtable.elements(); while (items.hasMoreElements()) { myobj item = items.nextElement(); System.out.println(item.X + " - " + item.Y.Z()); } 

However, Iterator is now preferred to Enumeration, as that quote from the javadoc shows :

NOTE: The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.

Using Iterator and Iterable, you can use, among other things, some synctatic sugar like for (Type t : myIterableOfTypeT).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.