Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: No ||= operator in Java?

Reply
Thread Tools

Re: No ||= operator in Java?

 
 
xarax
Guest
Posts: n/a
 
      07-27-2003
Joona I Palaste <(E-Mail Removed)> wrote in message news:<bg06ek$ms2$(E-Mail Removed)>...
> I recently got a compile-time error a piece of code similar to this:
>
> public class Foobar
> {
> private boolean flag = false;
> public boolean doStuff(Object obj)
> {
> return obj != null;
> }
> public void doStuff()
> {
> boolean result = doStuff(new Object());
> flag ||= !result;
> }
> }
>
> The errors came from the "||=" operator. It caused two errors: "Illegal
> start of expression" and "Not a statement".
> Isn't there a ||= operator in Java? The expression "a ||= b" would mean
> the same as "a = a || b" except that a was only evaluated once.
> The same would apply for the &&= operator. Isn't there a &&= operator in
> Java either?


If you read the JLS, you'll see that for booleans, you
simply use "a |= b;" and "a &= b;", etc. Java is smart
enough to notice that you are using booleans and do
the right thing.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-27-2003
On 27 Jul 2003 08:58:03 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (xarax) wrote or quoted
:

>If you read the JLS, you'll see that for booleans, you
>simply use "a |= b;" and "a &= b;", etc. Java is smart
>enough to notice that you are using booleans and do
>the right thing.


if b is a method, what is the "right thing" if a is true?
Evaluate it or not? With |= it must evaluate it regardless.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
T::operator int () const ambiguous with T::operator Handle () const? Tim Clacy C++ 15 05-30-2005 02:14 AM
Member operators operator>>() and operator<<() Alex Vinokur C++ 3 03-20-2005 03:11 PM
operator*(Foo) and operator*(int) const: ISO C++ says that these are ambiguous: Alex Vinokur C++ 4 11-26-2004 11:46 PM
Operator overloading on "default" operator John Smith C++ 2 10-06-2004 10:22 AM
Q: operator void* or operator bool? Jakob Bieling C++ 2 03-05-2004 04:27 PM



Advertisments