Results 1 to 10 of 10
  1. #1
    Blasz is offline Member
    Join Date
    Aug 2010
    Posts
    16
    Rep Power
    0

    Default Java Syntax If statement

    I was wondering if there was a shorter way of typing,

    Java Code:
    if(a==this||a==that)

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default

    It short enough for me :) what's the real problem with that?

  3. #3
    Blasz is offline Member
    Join Date
    Aug 2010
    Posts
    16
    Rep Power
    0

    Default

    my "this" and "that" are very long and i can't go over the 80 character width so it effectively adds unnecessary lines to my code.

    I tried if(a==(this||that)) but it didnt work.

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default

    You can always refactor your very long "this" and "that" expression into methods which you can call from the if statement.
    Last edited by wsaryada; 09-01-2010 at 10:14 AM.

  5. #5
    Blasz is offline Member
    Join Date
    Aug 2010
    Posts
    16
    Rep Power
    0

    Default

    Ok thanks for that. Now a totally different question.

    How can i catch a ArithmeticException, i try

    catch(ArithmeticException)

    but it doesnt recognise ArithmeticException.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    What do you mean by "doesn't recognise".
    When you get exceptions or compilation errors you really need to post the exact error you are getting.

  7. #7
    Blasz is offline Member
    Join Date
    Aug 2010
    Posts
    16
    Rep Power
    0

    Default

    Sorry i figured it out, I wasnt using try {}, and also i didnt put an identifier after the arithmeticexception,

    eg. ArithmeticException e

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    But that's not really mean "dosen't recognize". If you have a look at your error message then you can find the most suitable word for that. Try to stick with them. :)

  9. #9
    Blasz is offline Member
    Join Date
    Aug 2010
    Posts
    16
    Rep Power
    0

    Default

    Sorry about that, the proper error was "ArithmeticException cannot be resolved".

    All good now though :)

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Specific syntax? java.util.regex.Pattern$Node
    By lmhelp2 in forum New To Java
    Replies: 1
    Last Post: 04-09-2010, 11:32 AM
  2. Java syntax I don't understand - assignment
    By poet in forum New To Java
    Replies: 2
    Last Post: 09-19-2009, 06:47 AM
  3. Java JDBC/MySQL appropriate Syntax
    By thelinuxguy in forum Advanced Java
    Replies: 7
    Last Post: 02-10-2009, 07:57 PM
  4. Replies: 4
    Last Post: 06-25-2008, 08:09 PM
  5. JavaScript to Java Statement
    By mutuah in forum Advanced Java
    Replies: 0
    Last Post: 08-08-2007, 05:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •