Java SneakyThrow of exceptions, type erasure

If you compile it with -Xlint you’ll get a warning: c:\Users\Jon\Test>javac -Xlint SneakyThrow.java SneakyThrow.java:9: warning: [unchecked] unchecked cast throw (T) ex; ^ required: T found: Throwable where T is a type-variable: T extends Throwable declared in method <T>sneakyThrowInner(Throwable) 1 warning That’s basically saying “This cast isn’t really checked at execution time” (due to type erasure) … Read more

Why does Double.NaN==Double.NaN return false?

NaN means “Not a Number”. Java Language Specification (JLS) Third Edition says: An operation that overflows produces a signed infinity, an operation that underflows produces a denormalized value or a signed zero, and an operation that has no mathematically definite result produces NaN. All numeric operations with NaN as an operand produce NaN as a … Read more

Why can not I add two bytes and get an int and I can add two final bytes get a byte?

From the JLS 5.2 Assignment Conversion 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 the type of the variable is byte, short, or char, and the value of the constant expression is representable in the type of … Read more