Java 19
Divide Exact
System.out.println(Integer.MIN_VALUE/-1);
try {
System.out.println(Math.divideExact(Integer.MIN_VALUE, -1));
} catch(ArithmeticException e) {
System.out.println("Overflow");
}
-2147483648
Overflow
Snippet Javadoc
/**
* The following code shows how to use {@code Optional.isPresent}:
* {@snippet :
* if (v.isPresent()) {
* System.out.println("v: " + v.get());
* }
* }
*/
public void myMethod() {
// ...
}
/**
* The following code shows how to use {@code Optional.isPresent}:
* {@snippet file="ShowOptional.java" region="example"}
*/
ShowOptional.java
public class ShowOptional {
void show(Optional<String> v) {
// @start region="example"
if (v.isPresent()) {
System.out.println("v: " + v.get());
}
// @end
}
}