2 ms·
As a C++ programmer but not a Java programmer, why is it reasonable for Java to consider nonsensical types (where constraints are violated) to be valid but just
by amluto 10y ago
As a C++ programmer but not a Java programmer, why is it reasonable for Java to consider nonsensical types (where constraints are violated) to be valid but just not instantiatable? Wouldn't it be better to reject the type entirely? Then you couldn't have a null object of the type since the type itself is ill-formed.
- TJSomething 10y agoFor C++, one kind of nonsensical types is abominable function types, which are bare functions with cv-qualifiers [1] [2]. [1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0172r0.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p017... [2] https://news.ycombinator.com/item?id=10935171 https://news.ycombinator.com/item?id=10935171
- amluto 10y agoThat's a rather different issue. Abominable types are annoying and mostly worthless, but there's nothing inherently wrong with code containing a type variable that refers to the type. Java's screwy generic instantiations are types that violate constraints by merely being named. I'm not saying that C++'s type system is great. I'm just saying that Java's problem mystifies me.