Wie bekomme ich es hin das die Referenzen in der equals Methode übertragen werden in die andere Klasse.
Hier bei "if ( ??????? != otherMedium )" liegt mein Problem. Wie bekomme ich die anderen Referenzen da rein?
Die Klasse MediaAdmin darf ich nicht verändern.
Code:
package mediaadmin;
public class MediaAdmin {
static MediaAdmin singleInstance;
private MediaAdmin() {
}
void testMedium() {
Medium aMedium_1 = new Medium(11, "aaa");
Medium aMedium_2 = new Medium(11, "bbb");
Medium aMedium_3 = new Medium(22, "aaa");
Medium aMedium_4 = new Medium(11, "aaa");
aMedium_1.print();
System.out.println();
System.out.println(" comparing media:");
boolean comp = aMedium_1.equals(aMedium_2);
System.out.println(" medium_1, medium_2: " + comp);
comp = aMedium_2.equals(aMedium_3);
System.out.println(" medium_4, medium_3: " + comp);
comp = aMedium_1.equals(aMedium_4);
System.out.println(" medium_1, medium_4: " + comp);
return;
}
Java:
package mediaadmin;
public class Medium {
int id;
String title;
// define a constructor that sets the values of
// the members id and title
Medium(int _id, String _title) {
id=_id;
title=_title;
}
void print() {
// print out the id and the title
System.out.print(" Medium, id: " + id);
System.out.print(", title: " + title);
}
boolean equals(Medium otherMedium){
// This method returns true if the members
// of this object hold the same values
// as the members of the other object.
// Otherwise it returns false.
// Hint: the clearest way is to test for inequality:
if ( ??????? != otherMedium ) {
return false;
}
else{
return true;
}
}
}
Hier bei "if ( ??????? != otherMedium )" liegt mein Problem. Wie bekomme ich die anderen Referenzen da rein?
Die Klasse MediaAdmin darf ich nicht verändern.