Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Observer's code example  RSS feed

 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Day,

I tried to run the following code example at http://www.devx.com/tips/Tip/22592.

The code is not totally clean and I tried to improve it. Still the output doesn't seem right:

A change has happened and new salary is ObserverJDK.Employee@14f8dab

Here is the slightly modified code:



Any ideas?

Thanks,
Dan

[ March 08, 2005: Message edited by: Dan Drillich ]
[ March 08, 2005: Message edited by: Dan Drillich ]
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I got it:



But I'm not clear about the role of the parameter arg.

-- Dan
 
Vaithiya Sundaram
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dan
Good day.

The argument of the update method is whatever argument you pass in the notifyObservers() method in the Observable class.
In your case, you passed "this" as argument thats why it is printing ObserverJDK.Employee@14f8dab

The following line will give your expected result:
notifyObservers(Float.toString(getSalary()));
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!