- hey wiz
- Jun 18, 2005
-
|
adante posted:
ok, I am feeling a little silly to ask this, but could you provide me with EXACT CODE WHICH WILL COMPILE to do what I want, because I cannot see how to apply the bindings method (which is an engine method to the object o in my previous code listing.
What else do you want, he pretty much gave you the code. If you want to iterate over each entry, probably you will want something like this:
code:for (Map.Entry<String,Object> e: bindings) {
String key = e.getKey();
Object value = e.getValue(); // equivalent to bindings.get(key)
System.out.println("key: " + key + "\tvalue: " + value);
}
Be careful if you need to remove any elements from this map. You either need to do it using an iterator, or by copying all the keys to a second list/set and then call first.removeAll(second) after you finish iterating. Otherwise you will see a ConcurrentModificationException.
|
#
¿
Apr 18, 2008 06:56
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
Apr 27, 2024 06:40
|
|
- hey wiz
- Jun 18, 2005
-
|
Let me see if I'm on the same page with you
adante posted:
code: key : type : value
x : java.lang.Double : 1.0
y : java.lang.String : hello
z : java.lang.Boolean : false
key : this you are getting correctly.
type: this should be as simple as value.getClass().getName()
value: this is where you are stuck.
adante posted:
code:key: context value: javax.script.SimpleScriptContext@b23210
key: foo value: [object Object]
key: print value: sun.org.mozilla.javascript.internal.InterpretedFunction@f4f44a
If you were working on simple classes such as String, Boolean, Double as you mentioned in the example, you could just print value.toString(). However, it seems like you are trying to print the value of Objects that don't have a friendly toString() method. These objects may still have a method which will print exactly what you want, but for each class it would be different. If this was the case, how would you determine which method to call on which class to print what you want?
|
#
¿
Apr 19, 2008 20:47
|
|
- hey wiz
- Jun 18, 2005
-
|
if (failures >= formatStrings.length) throw;
should be
if (failures >= formatStrings.length) throw ex;
|
#
¿
Jul 10, 2008 06:15
|
|
- hey wiz
- Jun 18, 2005
-
|
I think you are missing the point adante. If you use a queue, even though you have multiple threads, it's only going to allow one thread to DoStuff() at a time, so you don't have to worry about readLine() blocking. To reiterate what Incoherence said, thread pools and a queue definately sound like the way to go.
|
#
¿
Aug 24, 2008 17:11
|
|