Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 912563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:24:12+00:00 2026-05-15T17:24:12+00:00

How does Java handle arguments separated by | ? for example private void foo(int

  • 0

How does Java handle arguments separated by | ?

for example

private void foo(int i) {
    System.out.println(i);
}

private void bar() {
    foo(1 | 2 | 1);
}

Which would give the output

3

I’ve seen this used in SWT/JFace widget constructors. What I can’t figure out is how the value of i is decided.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:24:13+00:00Added an answer on May 15, 2026 at 5:24 pm

    The | is a bitwise or-operator.

    foo(1 | 2 | 1);
    

    means call foo with the argument 1 bitwise-or 2 bitwise-or 1.

    • 1 in binary is 01
    • 2 in binary is 10

    Bitwise or of 01 and 10 is 11 which is 3 in decimal.

    Note that the | operator can be used for booleans as well. Difference from the || operator being that the second operand is evaluated even if the first operand evaluates to true.

    Actually, all bitwise operators work on booleans as well, including the xor ^. Here however, there are no corresponding logical operator. (It would be redundant, since there is no way of doing a “lazy” evaluation of ^ 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A java class does something like the following public class Foo { private final
Does java has library exception class which means actually not an error, but good
How does Java handle integer underflows and overflows? Leading on from that, how would
How does Eclipse handle excluding Java files in the project?? In C# the list
Does anyone knows a good business calendar library in java? It should handle easy
How does Java, Kotlin, and Android handle returning an Array value at a given
How does the Java compiler handle the following switch block ? What is the
If a website is written in Java how does the server handle Java updates,
Does Java guarantee array initialization? Let's say I use the code char[] uuid =
Does Java have an equivalent to .NET resource (.resx) files for localization? In .NET,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.