JDK-5100940 : Put Listeners On Any Class Attribute
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-09-13
  • Updated: 2006-11-15
  • Resolved: 2006-11-15
Related Reports
Relates :  
Description
Name: js151677			Date: 09/13/2004


A DESCRIPTION OF THE REQUEST :
It would be great to have a language enhancement in Java, which allows attaching listeners to ordinary attributes (and to methods) of any class instance. With that mechanism it would be much simpler to build MVC models.

JUSTIFICATION :
This would make Java better than C#

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The runtime performance of a normal attribute change (or method call) should not change, unless at least one listener is attached to it.

Object a = new MyClass();

a.addAttributeListener("attributeName", new AttributeListener() {
 public void valueChange(AttributeChangeEvent ev) {
   Object ov = ev.oldValue()
   Object nv = ev.newValue();
 }
}
)

a.addMethodListener("methodName", paramClassArray, new MethodListener()....);
(Incident Review ID: 310509) 
======================================================================

Comments
EVALUATION This is the kind of feature you might find in a dynamic language, where all message sends (including field access/update) can be intercepted. It certainly requires runtime support. But it's not an essential object-oriented concept, and people are sufficiently familiar with listener and observer patterns that I'm not prepared to support this request in Java. (If properties are added to Java, such patterns would be slightly easier to code.)
15-11-2006