-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
1.4.2
-
x86
-
windows_2000
Name: gm110360 Date: 04/18/2003
A DESCRIPTION OF THE REQUEST :
The class MidiMessage and it's subclasses doesn't override
the .equals() method of Object.
.equals should check for the same *contents* of an object.
So it's needed to override it at least for such important
containers.
JUSTIFICATION :
Everywhere in the API's there are .equals() methods for comparing
the content (Point, Color etc.etc.)
But the entire sound-API is missing it, so you can't compare
Messages (Short and Sysex-Messages) without implementing own methods.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Correct implementation of .equals() method - comparing the
contents and not the pointer to the object.
.equals compares only the reference (the default behav. of Object.equals())
---------- BEGIN SOURCE ----------
/*
* EqualTest.java
*
* Created on 12. April 2003, 14:13
*/
import javax.sound.midi.*;
/**
*
* @author Gerrit Gehnen
*/
public class EqualTest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ShortMessage msg1,msg2;
msg1=new ShortMessage();
try{
msg1.setMessage(ShortMessage.NOTE_ON,1,64,64);
// Duplicate the original Message
msg2=(ShortMessage)msg1.clone();
if (msg1.equals(msg2))
{
System.out.println("OK: Is equal!");
System.exit(0);
}
else
{
System.out.println("ERROR: Is not equal!");
System.exit(1);
}
}catch (Exception e){e.printStackTrace();}
}
}
---------- END SOURCE ----------
(Review ID: 184030)
======================================================================
- duplicates
-
JDK-4663506 RFE: override equals() method in info classes
-
- Closed
-