You're completely right. Here's the example function signature from the blog post:
fn greet() (string) (error)
In Java, you can write exactly the same thing:
String greet() throws Error
The "implicit error propagation also looks exactly the same.
fn main() () (error) {
s := greet() // <-- Implicit error propagation
println(s)
}
In Java:
void main() throws Error {
var s = greet(); // <-- Implicit error propagation
System.out.println(s);
}
The case with a question mark after the error is the only case not covered by Java.
The final case, with explicit error handling:
fn main() {
s := greet() // <-- failure result can not be propagated
println(s)
}
Also looks exactly the same in Java:
void main() {
var s = greet(); // <-- compilation error: must handle Error
}
EDIT: ok, let's mention also RuntimeException! In Java, you don't need to declare those (and subtypes) in your signature (but you can) and even if you do, you don't need to handle them. That's because the original idea was that RuntimeException was to represent programmer mistakes that should never be caught. The Java community ended up using it exactly the opposite way because everyone complained about explicit error handling being too much of a chore, so making most Exceptions subtype RuntimeException became common so now you can't assume that you don't need to catch them (but the compiler won't force you to)... other JVM languages like Groovy and Kotlin just eliminated checked Exceptions completely for that reason. It's a bit amusing to me how "checked errors" in general has made a comeback in Go and Rust, and in many newer languages like Zig (and now this one) as well. I think that the way Rust does it seems to be the best "compromise". It's almost like Java's checked Exceptions, but it's added sugar on top to make it much easier, while still explicit, to propagate errors. It's a tiny difference , but it seems that tiny difference makes ALL the difference for people (just see how people love Rust and its error handling, but loathe Java's).
Oracle guideline: https://docs.oracle.com/javase/tutorial/essential/exceptions...