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

  • Home
  • SEARCH
  • 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 7067577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:13:08+00:00 2026-05-28T05:13:08+00:00

I have a piece of code like follows public class Test{ public static void

  • 0

I have a piece of code like follows

public class Test{
               public static void main(String[] args) {
                  System.out.println(true?false:true == true?false:true);
                                                -----------------------
               }
            }

The output is false. If you are using Eclipse you get a wavy (dashed here) line and warning like “Comparing identical expressions”. Note the start of the wavy line.

I changed the code to the following

              public class Test{
               public static void main(String[] args) {
                  System.out.println((true?false:true) == (true?false:true));
                                     ---------------------------------------
               }
            }

The output is true. If you are using Eclipse you get a wavy (dashed here) line and warning like “Comparing identical expressions”. Note the start of the wavy line now.

Why the difference?

  • 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-28T05:13:09+00:00Added an answer on May 28, 2026 at 5:13 am

    In case your problem is the difference of outcomes, this is because of the order of precedence of the operators you use. Check here for details. According to that order of precedence:

    true ? false : true == true ? false : true
    

    is the same as this:

    true ? false : ((true == true) ? false : true)
    

    so it will always evaluate to false. You could put anything after the colon since it’s never evaluated anyway (if I remember correctly and the ternary operator uses lazy evaluation); the reason for this is that

    true ? A : B
    

    always evaluates to A.


    On the other hand,

    (true ? false : true) == (true ? false : true)
    

    will have both sides of the comparison operator == evaluate to false, so

    false == false
    

    which is a true statement.

    So the difference here is the order in which the operators are evaluated, which is determined by the parentheses you use and, if there is ambiguity that isn’t resolved by parentheses, by the order of precedence of the operators that are used.


    In general, the ternary operator “? :” works like this

    A ? B : C
    

    If A is true, evaluate to B, else evaluate to C. A has to be a boolean expression, B and C can be whatever you want; you’ll have to deal with type mismatches though if you want to assign the evaluated value to a variable and they are of different types.

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

Sidebar

Related Questions

I have a piece of code like this: Class Program { static StreamReader sr
I have a piece of code like this class Base { public: Base(bool _active)
I have a piece of code like the following: public class ActivityHelper { public
Lets say i have a piece of code like this: test pattern | pattern
I have a piece of code like this: set<string>::iterator it1; set<string>::iterator it2; pair<set<string>::iterator,bool> ret;
I have a piece of code looking like this : TAxis *axis = 0;
I have this piece of code #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h>
I have a piece of javascript code like this right now. document.getElementById(pos).style.backgroundColor='#800080'; I want
I have a piece of code that looks like this: Dir.new(path).each do |entry| puts
I have a piece of code like this try { RegistryKey regKey = Registry.LocalMachine.CreateSubKey(SOFTWARE\\xxxx\\yyyyy);

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.