Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7679857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:58:35+00:00 2026-05-31T17:58:35+00:00

In Java, what is the most elegant way for an object to fire an

  • 0

In Java, what is the most elegant way for an object to fire an event whenever any property of an object changes?

My domain model has several objects like

class MyClass {

    String id;
    String name;
    Collection<MyThing> mythings= new HashSet<MyThing>();
    // more fields...
    Date lastUpdated;

    //constructor, getters and setters, etc
}

I need lastUpdated to be set to “today” whenever any of the properties (id/name/mythings) changes.

I would prefer a solution that is not JDO-specific, and definitely don’t want this logic in the datastore (auto-timestamp column in the RDBMS etc).

I could put

this.lastUpdated = new Date();

in every setter, or fire a custom event in every setter, but that’s ugly and error-prone.

Is there a more elegant solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:58:36+00:00Added an answer on May 31, 2026 at 5:58 pm

    You can implement the PropertyChangeListener interface and register your interest on the part of clients. It’s been part of the Java Bean specification since 1.0.

    They aren’t all about UI elements. They were conceived as a way to match VB-like features for IDEs (e.g the Bean Factory).

    http://docs.oracle.com/javase/tutorial/uiswing/events/propertychangelistener.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I heard most elegant property of java is Garbage Collection I wanna know does
What's the most efficient way in Java to get the 50 most frequent words
What is the most efficient way to reverse a string in Java? Should I
What is the most concise way of converting a java.util.List into a normal JavaFX
In Java, what's generally the most accepted way to organize a class in terms
What is the most elegant way of bubble-sorting in F#? UPDATE As pointed out
What is the most elegant way to get the size of a Regex.MatchIterator in
What is the most elegant way to convert a hyphen separated word (e.g. do-some-stuff)
So most Java resources when speaking of packages mention a com.yourcompany.project setup. However, I
I need to implement a browser based component (most likely java applet since it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.