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 8053887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:59:42+00:00 2026-06-05T07:59:42+00:00

It seems reasonable to not allow int a = 8; boolean b = (boolean)a;

  • 0

It seems reasonable to not allow

int a = 8;
boolean b = (boolean)a;

because that could lead to programmer errors, because the resulting boolean would be false for even integers, but why doesn’t a widening coercion, e.g. int a = true work?

Edit:

According to the JVM specification, Section 3.3.4:

The Java virtual machine encodes boolean array components using 1 to
represent true and 0 to represent false. Where Java programming
language boolean values are mapped by compilers to values of Java
virtual machine type int, the compilers must use the same encoding.

For example:

public static boolean returnFalse() {
    return false;
}

public static boolean returnTrue() {
    return true;
}

compiles to:

public static boolean returnFalse();
  Code:
     0: iconst_0
     1: ireturn

public static boolean returnTrue();
  Code:
     0: iconst_1
     1: ireturn
  • 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-06-05T07:59:44+00:00Added an answer on June 5, 2026 at 7:59 am

    The internal representation isn’t relevant.

    Java is strongly-typed: an int isn’t a boolean, and a boolean isn’t an int.

    This was a design decision–if you want to use true/false, use booleans; that communicates something.

    If you want to use an integer to represent true/false, use mathematical comparisons–that’s fine too.

    The language doesn’t support direct conversion because it doesn’t, by design.


    Regarding the JVM spec and the internal representation of booleans, this sentence is interesting:

    Where Java programming language boolean values are mapped by compilers to values of Java virtual machine type int, the compilers must use the same encoding.

    To me, that reads:

    If the compiler/VM is using a VM integer to represent true/false, then it must use the 1/0 convention. With the implication being: If the compiler/VM isn’t using a VM integer for true/false, this isn’t a requirement.

    Clarification on this point would be interesting, but ultimately not related, really.

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

Sidebar

Related Questions

Does Git support any commands that would allow me to commit directly from a
I'm not sure if it's possible but it seems a little bit reasonable to
Seems that even after unchecking the option in the PyDev/Debug preferenecs pane to launch
The following code seems reasonable to me. It should create the object and then
I'm seeing a behaviour in Firefox which seems to me unexpected. This is not
I have a website that would ideally be accessed by users who have downloaded
It seems to me that, in some ways, Java is where C was a
Seems like cuke doesn't show the full error message (at least when problem occurs
Seems when I make move refactoring all my junit tests lays on its old
Seems like a standard approach for an ioc when given a scenario like (C#

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.