Index: [thread] [date] [subject] [author]
  From: Jason Grosland <jcg3@cs.duke.edu>
  To  : 
  Date: Tue, 27 Apr 1999 12:28:57 -0400

Re: instanceof

When you get an Object passed in to any function, you'll probably want to
do _something_ with it, why else would you include it as a parameter?
You'd probably want to do something like the following:

public void update(Observable o, Object arg)
{
  if(arg instanceof java.awt.Canvas) {
    ((java.awt.Canvas)arg).update();
  }
  else if(arg instanceof GamePlayer) {
    ((GamePlayer)arg).takeTurn();
  }
  // etc.
}

It's kinda necessary if you want to do anything with the Object.
...jason

  { jcg3@cs.duke.edu * www.duke.edu/~jcg3 * 919.613.1354 * 108 House P }

On Mon, 26 Apr 1999, Philip K. Warren wrote:

> Just a quick question on instanceof.  Within the observable class, you have
> the option of passing an optional "Object arg" to all of the observers.  Is
> it ok to use the instanceof in those places to tell what was passed as an
> argument, or should we not use this functionality at all?
> 
> -- Philip
> 
> 
> 
> 



Index: [thread] [date] [subject] [author]