1
$\begingroup$

This is a follow-up question to my previous question

I have been reading this post and it comes up with the following example showing how Java type system is unsound:

interface IFoo<T> {
    Number foo(T t);
}
class Foo<T extends Number> implements IFoo<T> {
    public Number foo(T t) { return t; }
}
Number bar(IFoo<String> foos) { return foos.foo("NaN"); }

And in the same post it talks about how we can never instantiate such Foo<String>. But does it really prove type system being unsound?

Also, based on the answer to the previous question, to prove type "Preservation" not happening, we need to prove type system being unsound. But this example can never be "evaluted" and then we check if after evaluation type is preserved because there is no such a Foo<String>. I am very confused.

$\endgroup$

1 Answer 1

-2
$\begingroup$

The Java type system is strong. There are simply some errors that could, in theory, be reported at compile time that the Java Language Specification does not explicitly prohibit, and thus they are reported at run-time instead of compile time.

This really isn't that complicated, and it's all spelled out in the Java Language Specification and the Java Virtual Machine Specification. Please read those, then any of your remaining questions should be answerable.

https://docs.oracle.com/javase/specs/

$\endgroup$
2
  • $\begingroup$ Yes. That's how I learned the topic, before writing a Java assembler ('96) and compiler ('97). If you have a better approach, please do share it. $\endgroup$ Commented Feb 5, 2023 at 0:32
  • $\begingroup$ Sure, but the question wasn't "how do I learn to program in Java" (which you have answered quite nicely, thank you for the link). The question was more like: "How do I understand the intricate details of how type safety is accomplished by the combination of the Java language design, the compiler, the verifier, and the runtime." (That would have been the question had he understood what to ask.) Also, congratulations on the professorship. Where do you teach? What's your favorite topic to teach? $\endgroup$ Commented Feb 5, 2023 at 20:33

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.