Overflowing Short in java

What’s happening is that your number is wrapping around. More specifically, you’ve got a number 30,000, which in binary is: 0111 0101 0011 0000 When you add it to itself, and carry the 1’s, you get: 1110 1010 0110 0000 (Note: it’s very easy to multiply a number by 2 in binary — just shift … Read more

Java: Why can’t I cast int to Long

I think the question was not about casting primitives and wrappers in general. The question was about difference between casting int to java.lang.Long and int to java.lang.Short for example. JLS: “In addition, if the expression is a constant expression (§15.28) of type byte, short, char or int: A narrowing primitive conversion may be used if … Read more

Setting Short Value Java

In Java, integer literals are of type int by default. For some other types, you may suffix the literal with a case-insensitive letter like L, D, F to specify a long, double, or float, respectively. Note it is common practice to use uppercase letters for better readability. The Java Language Specification does not provide the … Read more

Pseudo-destructor call does not destroy an object

But it is not true, why? §5.2.4/1: The only effect is the evaluation of the postfix-expression before the dot or arrow. Where the postfix-expression is the expression of the object for which the call takes place. Thus a pseudo destructor call, as a call to a trivial destructor, does not end the lifetime of the … Read more

tech