No idea about ((A)o) | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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.

30th Aug 2016, 11:17 AM
Edson Palencia Vanegas
Edson Palencia Vanegas - avatar
7 Respostas
+ 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;
30th Aug 2016, 4:00 PM
Tiger
Tiger - avatar
+ 1
Thank you Tiger. I appreciate you took the time to explain it, it helps me a lot. Cheers.
30th Aug 2016, 4:11 PM
Edson Palencia Vanegas
Edson Palencia Vanegas - avatar
+ 1
you are welcome @Edd
30th Aug 2016, 4:13 PM
Tiger
Tiger - avatar
+ 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)); } }
3rd Nov 2016, 2:21 PM
ABINAYA SRI.A.M
ABINAYA SRI.A.M - avatar
+ 1
thank you
5th Feb 2017, 8:04 AM
Abdulhameed Alhababi
Abdulhameed Alhababi - avatar
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)); } }
7th Apr 2018, 2:47 PM
Jenu Mathew
Jenu Mathew - avatar
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)); } }
16th Dec 2018, 8:27 AM
Likhon
Likhon - avatar