• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Observer's code example

 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I got it:



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

-- Dan
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()));
 
Message for you sir! I think it is a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic