Re: No ||= operator in Java?

Discussion in 'Java' started by xarax, Jul 27, 2003.

  1. xarax

    xarax Guest

    Joona I Palaste <> wrote in message news:<bg06ek$ms2$>...
    > 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.
     
    xarax, Jul 27, 2003
    #1
    1. Advertising

  2. xarax

    Roedy Green Guest

    On 27 Jul 2003 08:58:03 -0700, (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.
     
    Roedy Green, Jul 28, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jakob Bieling

    Q: operator void* or operator bool?

    Jakob Bieling, Mar 5, 2004, in forum: C++
    Replies:
    2
    Views:
    594
    Rob Williscroft
    Mar 5, 2004
  2. John Smith
    Replies:
    2
    Views:
    433
    Ivan Vecerina
    Oct 6, 2004
  3. Alex Vinokur
    Replies:
    4
    Views:
    3,061
    Peter Koch Larsen
    Nov 26, 2004
  4. Alex Vinokur
    Replies:
    3
    Views:
    5,042
    Jeff Schwab
    Mar 20, 2005
  5. Tim Clacy
    Replies:
    15
    Views:
    2,705
    Kanenas
    May 30, 2005
Loading...

Share This Page