Page 1 of 1

[HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Posted: Wed Oct 10, 2018 4:01 am
by Arold Aroldson
In table in page 113. Boolean flag=false; sout(false != flag); prints false. You have a mistake in book.

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Posted: Wed Oct 10, 2018 4:20 am
by admin
Yes, it has been fixed in update 6 released on Oct 7th 2018.

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Posted: Mon Dec 03, 2018 7:41 pm
by Username987654
instanceof discussion:
It returns true if the object pointed to by the reference
variable on the left is of the type (or a subtype) of the type given on
the left and false otherwise.
should be
It returns true if the object pointed to by the reference
variable on the left is of the type (or a subtype) of the type given on
the right and false otherwise.
?

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Posted: Tue Dec 04, 2018 9:11 am
by admin
Correct. Will add to errata asap.
thank you for your feedback!

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Posted: Tue Dec 04, 2018 10:45 am
by Username987654
ok. Thank you for another excellent Enthuware product and excellent customer service.

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Posted: Sun Jul 07, 2019 8:20 pm
by Username987654

Code: Select all

Object obj = new Double(10);//
System.out.println(obj != 10); //1  can’t compare a reference with a number
int a = 10; Double d = 10.0;
System.out.println(a != d);//2  prints false (book example)
I don't feel as if I have burned 1) into my mind completely. Why doesn't the compiler at 1) not have to allow for the possibility of a situation like 2) ?

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Posted: Sun Jul 07, 2019 8:56 pm
by admin
How can a reference be same as a primitive? obj is a reference. It can never be same a integer 10. Same with a and d. a is an primitive variable and d is a reference variable. Both are inherently different things and can never point to the same object (which is what == checks). The compiler knows that this comparison is nonsensical and most probably a programming mistake.

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Posted: Sun Jul 07, 2019 11:29 pm
by Username987654
admin wrote:
Sun Jul 07, 2019 8:56 pm
How can a reference be same as a primitive? obj is a reference. It can never be same a integer 10. Same with a and d. a is an primitive variable and d is a reference variable. Both are inherently different things and can never point to the same object (which is what == checks).
My blind spot is trying to understand why the compiler does not treat these the same.
admin wrote:
Sun Jul 07, 2019 8:56 pm
The compiler knows that this comparison is nonsensical and most probably a programming mistake.
I think the compiler does not treat these the same because of a very important piece of information that apparently I overlooked:
When used on two primitive values or a primitive value and a primitive wrapper, they check whether the two values are same or not.
The one that compiled (a != d) adhered to this rule, as does the first example box mentioned for ==, != (Binary) in the book? Whereas the other (obj != 10) did not adhere to this rule, as does the second example box mentioned for ==, != (Binary) in the book?. Thus, the compiler complained. Correct?

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Posted: Sun Jul 07, 2019 11:40 pm
by admin
Yes, sounds logical.

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Posted: Sun Jul 07, 2019 11:49 pm
by Username987654
Thanks!

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Posted: Mon Oct 07, 2019 1:11 pm
by DazedTurtle
In the bit about the = operator:
It simply copies the value on the left to the variable on the right.
Pretty sure you switched left and right there.

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Posted: Mon Oct 07, 2019 9:16 pm
by admin
DazedTurtle wrote:
Mon Oct 07, 2019 1:11 pm
In the bit about the = operator:
It simply copies the value on the left to the variable on the right.
Pretty sure you switched left and right there.
Yes, added to the errata only a couple of days ago.