3 ms·
It's not a type system loophole in the sense that the type system is supposed to contain subtyping as a feature. In Java you could be unhelpful and pass every a
by kccqzy 2y ago
It's not a type system loophole in the sense that the type system is supposed to contain subtyping as a feature. In Java you could be unhelpful and pass every argument as type Object. (Of course the language allows you to cast the type afterwards.) That's not the fault of the type system it's the people using it. Do you hear people proposing to ban the use of Object in function arguments? No? Because it's a style issue not a type system issue.
- MBCook 2y agoYou’re right but I think that’s pretty self-defeating so people wouldn’t really do it. But there’s a pretty good argument that the way exceptions are implemented in Java makes the easiest thing to do simply be to start tacking “throws Exception“ on the end of tons of methods once you start to have trouble. Everywhere I’ve worked you start to see that in chunks of the code base. You don’t have to. It’s certainly avoidable. But as things get more and more complicated people will just opt for that to save themselves time. Java’s design unintentionally encourage it when the going gets rough. Even when using an IDE that can add the correct types to the list for you, that’s what people reach for.