Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
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.

Adbot
ADBOT LOVES YOU

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?

hey wiz
Jun 18, 2005

if (failures >= formatStrings.length) throw;

should be

if (failures >= formatStrings.length) throw ex;

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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply