Re: Parentheses issue
- From: Patrick May <pjm@xxxxxxx>
- Date: Sat, 30 Dec 2006 21:35:00 -0500
"jupiter" <jupiter49byebyeSpam@xxxxxxx> writes:
Can somebody explain in English
Will you accept geeklish?
why the cast of obj to
AccountBalance works here?
if(obj instanceof AccountBalance &&
((AccountBalance)obj).getBalance() == this.balance) {
return true;
}
But doesn't work here?
if(obj instanceof AccountBalance &&
(AccountBalance)obj.getBalance() == this.balance) {
return true;
}
The object member operator ('.') has higher precedence than the
cast operator ('(...)'). The second form tries to call getBalance()
before casting obj to the AccountBalance type.
In the second snippet the compiler complains of "incompatible
operand types, AccountBalance and double"
The error message is certainly not descriptive.
Regards,
Patrick
------------------------------------------------------------------------
S P Engineering, Inc. | Large scale, mission-critical, distributed OO
| systems design and implementation.
pjm@xxxxxxx | (C++, Java, Common Lisp, Jini, middleware, SOA)
.
- Follow-Ups:
- Re: Parentheses issue
- From: jupiter
- Re: Parentheses issue
- References:
- Parentheses issue
- From: jupiter
- Parentheses issue
- Prev by Date: Question:
- Next by Date: Re: Question:
- Previous by thread: Re: Parentheses issue
- Next by thread: Re: Parentheses issue
- Index(es):
Relevant Pages
|