[HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]
Moderator: admin
-
- Posts: 21
- Joined: Mon Nov 20, 2017 8:00 am
- Contact:
[HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]
In table in page 113. Boolean flag=false; sout(false != flag); prints false. You have a mistake in book.
-
- Site Admin
- Posts: 10391
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]
Yes, it has been fixed in update 6 released on Oct 7th 2018.
-
- Posts: 95
- Joined: Sat Dec 26, 2015 6:37 pm
- Contact:
Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]
instanceof discussion:
should beIt 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.
?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.
-
- Site Admin
- Posts: 10391
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]
Correct. Will add to errata asap.
thank you for your feedback!
thank you for your feedback!
-
- Posts: 95
- Joined: Sat Dec 26, 2015 6:37 pm
- Contact:
Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]
ok. Thank you for another excellent Enthuware product and excellent customer service.
-
- Posts: 95
- Joined: Sat Dec 26, 2015 6:37 pm
- Contact:
Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]
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)
-
- Site Admin
- Posts: 10391
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]
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.
-
- Posts: 95
- Joined: Sat Dec 26, 2015 6:37 pm
- Contact:
Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]
My blind spot is trying to understand why the compiler does not treat these the same.admin wrote: ↑Sun Jul 07, 2019 8:56 pmHow 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).
I think the compiler does not treat these the same because of a very important piece of information that apparently I overlooked:
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?When used on two primitive values or a primitive value and a primitive wrapper, they check whether the two values are same or not.
-
- Site Admin
- Posts: 10391
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]
Yes, sounds logical.
-
- Posts: 95
- Joined: Sat Dec 26, 2015 6:37 pm
- Contact:
-
- Posts: 26
- Joined: Wed Oct 02, 2019 1:42 pm
- Contact:
Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]
In the bit about the = operator:
Pretty sure you switched left and right there.It simply copies the value on the left to the variable on the right.
-
- Site Admin
- Posts: 10391
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]
Yes, added to the errata only a couple of days ago.DazedTurtle wrote: ↑Mon Oct 07, 2019 1:11 pmIn the bit about the = operator:
Pretty sure you switched left and right there.It simply copies the value on the left to the variable on the right.
Who is online
Users browsing this forum: __nelson__ and 183 guests