D Lor

Greenhorn
+ Follow
since Sep 20, 2006
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 D Lor

Hi,
Perhaps I'm going about this entirely the wrong way (in which case please inform me of this!); but assuming I'm on the right track, I can't for the life of me figure out how to properly encapsulate the details of my inner class through delegate methods in the outer class.

Here's the example code:

package some.package;

Public Class OuterClass {

private ArrayList<InnerClass> myList;
.
//constructor + getters,setters for various things
.
public addInnerClassItem(Map someMap) {
myList.put
}

private class InnerClass {
private Map<String, String> hashMap;
private InnerClass(Map <String, String> someMap) {
hashMap = new HashMap<String, String>(someMap);
.
//getters + setters + some other variables
.
}
}
}

Now, in some other file:

import some.package.OuterClass;

Main() {

OuterClass oC = new OuterClass();
Map<String, String> someMap = new HashMap<String,String>;
someMap.put("exampleKey", "exampleValue");
oC.addInnerClassItem(someMap);
iterator it = oC.getMyListIterator(); //retuns iterator to myList
while (it.hasNext() {
//how do I get access to the HashMap for the .next() instance of InnerClass?
//I want to get the key-value-pairs...
}
}

So as you can see (I hope...), I can't assing anything to the it.next() because within my scope, there is no notion of InnerClass - which is what it.next() returns. Is there a way to sort of "ignore" the fact that my scope doesn't know about InnerClass, but yet use it so that I can do something like:

HashMap = it.next().getHashMap() ??

Any thoughts are massively appreciated. I'm thinign the answer to this is that I don't want to use inner classes in this way. Which is fine...if you can point me in the direction of a better way to do this? I want to have some class that contains instances of another class. The end user (this is a library) needs to be shielded as much as possible from the inner class.

Cheers,
D.
17 years ago