public class Main
{
public static void main(String args[])
{
process(true ? 1 : 2L);
}
static void process(Object object)
{
System.out.println(object instanceof Integer);
}
}
My expected output is true .
But actual out put is false .
My understanding is between integral data types the largest type will be assigned. If so what is this called?
The then and else parts of true ? 1 : 2l
true ? 1 : 2l
are int
and long
. The result is the widest, long
, the the then-part is cast to long. See JLS .
In Computer Science a term for this is balancing types .
34 / 2.0 // double, more a case of _widening a type_.
c ? 2.0 : 34 // double
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.