> A Python class name is just as good a declaration of intentions as a Java class name.

Yes, it is just as good a declaration of intentions.

> But why should I trust an unverified declaration?

Wait a second though...

def foo(bar):
if !isinstance(bar, Baz):
throw WrongTypeException

THAT is somewhat equivalent to having:

public void foo(Baz bar);

The Java one gets verified without test cases (there's literally steps in the process with "Verifier" in the name), but the Python one does not.

Most Python code doesn't have all of its parameters laden with type checks, whereas Java code tends to have type names attached to its parameters. More importantly though, that Python type check doesn't actually get verified until runtime, and only on a case by case basis. The static type checks in Java will be done first at compile time, and then again during bind/load time. You still have to write code to verify that you never get a non-Baz "baz" for the Python function, and that's trickier than it looks.

> Finite discriminate unions are pretty trivial by any reasonable standards, and Java can only handle them by very cumbersome means (visitors), which people who value their time reasonably avoid.

You value your time, so because of cases where you'd like to return more than one type without a common parent type, you would throw out type checking entirely?...

> But `null` still exists, and it's used in several parts of the Java standard library.

So, Rust at least still has null as well (they say they don't, but in practice they have std::ptr::null and they also have None... now tell me that doesn't create more problems than it solves ;-), as there's this problem that reality is already filled with nulls.

In practice, what you are getting at is exactly what I pointed out earlier: Java is locked in to certain behaviours and interfaces that predate the current somewhat more sophisticated state of the type system.

> No, exceptions aren't reasonable. They don't show up in types, so you don't know what kinds of exceptions a particular procedure might throw.

They do for checked exceptions:

final java.sql.ResultSet foo = query.execute();
foo.getInt(1);

That's going to get you an int, a SQLException, a RuntimeException, or an Error depending on circumstance. While the Error & RuntimeException aren't checked by the compiler, the SQLException is, and you've got a fairly natural way of writing logic for it too. That's a very reasonable way of declaring that your function will return either an int or a SQLException. Without any test cases, the compiler will tell me if I'm not handling that SQLException case (much to my chagrin).

> Java's `Optional<T>` is hardly more satisfying: how do I simultaneously pattern-match over two or more optionals?

Generally, I haven't needed to. Usually the optional comes in a different stream or in a different stage of processing a stream.

However, for cases where you really have multiple optionals, you typically either pass them as parameters to lambda or create a named type that contains your Optional<T> types. Honestly, given the complexity of those cases, it isn't that great a burden compared to the logic you're going to bind to it...

> In any case, there exist many more interesting discriminated unions than can be expressed using only optionals and recursive types.

Might be more interesting yes... but for your typical coding context, not that important.