11. Calling Java

  • chapter 11 of 20
  • 1 min read

JVM toolchain only. This chapter needs dawn-selfhost.jar or a checkout's ./bin/dawn. The static dawnc compiles through C and refuses use java, so with it, skip to chapter 12.

use java "..." calls a Java class directly. Every Java call counts as !io, and a reference return type is wrapped in Option[T] automatically — null does not get into Dawn. Construct with .new, and call static methods on the class name.

use java "java.lang.Math"

pub fn main() -> Unit !io = {
  let n = Math.abs(-7)
  println(to_string(n))
}
7

See also: spec.en.md §9