Java: Comparing data types int and boolean


#1


Here is the line to which i'm referring.
" Equality operators do not require that operands share the same ordering. For example, you can test equality across boolean, char, or int data types. "
Here is the link.

https://www.codecademy.com/en/courses/learn-java/lessons/introduction-to-java/exercises/equality-operators?action=lesson_resume


System.out.println(2==true)

error:incomparable types:int and boolean


#2

Hi boolean value are true or false


#3

Right you are, boolean is not a numeric type.


#4

thanks for the response,
but see when we use the code

char myChar = 'A';
int myInt = -2;
System.out.println(myChar == myInt);

the output is false

shouldn't this also give error


#5

char and int are both numeric, so that's fine!

This explains what's going on:
https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.21
Reading just the bold paragraph probably says enough


#6

alphanumeric, aren't they? Containing letters and/or numbers?


#7

It's an unsigned short (16 bits, 0 to 65535)