Re: Parentheses issue



"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)
.



Relevant Pages

  • Re: Parentheses issue
    ... AccountBalance works here? ... if(obj instanceof AccountBalance && ... cast operator '). ... before casting obj to the AccountBalance type. ...
    (comp.lang.java.programmer)
  • Parentheses issue
    ... Can somebody explain in English why the cast of obj to ... AccountBalance works here? ... if(obj instanceof AccountBalance && ...
    (comp.lang.java.programmer)