+ 2
No idea about ((A)o)
Could someone please explain me the meaning of this line: return ((A)o).x == this.x I got confused with the class A inside the parenthesis with the 'o' Object..... I just don't get it.
7 ответов
+ 11
return ((A)o).x == this.x means return true if o.x == this.x.
 (A)o is simple casting object o into class A type.
the code can be split as following:
A a = (A)o;
return a.x == this.x;
+ 1
Thank you Tiger. I appreciate you took the time to explain it, it helps me a lot. Cheers.
+ 1
you are welcome @Edd
+ 1
Fill in the blanks to check whether the two objects of type A are semantically equal.
class A {
   private int x;
   public   equals(Object o) {
      ((A)o).x == this.x;
   } 
   public static void main(String[ ] args)  {
    A a = new A();
    a.x = 9;
    A b = new  ();
    b.x = 5;
    System.out.println(a. (b));
   }
}
+ 1
thank you
0
class A {
   private int x;
   public  boolean 
 equals(Object o) {
     return 
 ((A)o).x == this.x;
   } 
   public static void main(String[ ] args)  {
    A a = new A();
    a.x = 9;
    A b = new  A 
();
    b.x = 5;
    System.out.println(a. equals 
(b));
   }
}
0
class A {
   private int x;
   public boolean  equals(Object o) {
    return  ((A)o).x == this.x;
   } 
   public static void main(String[ ] args)  {
    A a = new A();
    a.x = 9;
    A b = new A ();
    b.x = 5;
    System.out.println(a.equals (b));
   }
}









