7 ms·
>which it isn't NullPointerException is a run time type error and quite common. I'm not convinced it's a problem C++ adequately solves, though.
by koala_man 8y ago
>which it isn't
NullPointerException is a run time type error and quite common. I'm not convinced it's a problem C++ adequately solves, though.
- pvg 8y agoYou can take a view of types that is broader than the one Java actually uses such that an NPE is a 'runtime type error' but you can do that with lots of runtime errors. It's not what the poster is talking about.
- koala_man 8y agoYou sure could -- Coq programmers might say that any error is a runtime type error. I don't think NPEs go much beyond Java's own definition though. If you have a reference to a String, it's not necessarily of type String. You'd get a runtime error if you try to treat it as such, just like you would in Python. This is not the case in C++, though obviously it's not an example of template metaprogramming.