Why can’t I inherit from int in C++?

Neil’s comment is pretty accurate. Bjarne mentioned considering and rejecting this exact possibility1: The initializer syntax used to be illegal for built-in types. To allow it, I introduced the notion that built-in types have constructors and destructors. For example: int a(1); // pre-2.1 error, now initializes a to 1 I considered extending this notion to … Read more

Why does Java not allow foreach on iterators (only on iterables)? [duplicate]

So I have a somewhat reasonable explanation now: Short version: Because the syntax also applies to arrays, which don’t have iterators. If the syntax were designed around Iterator as I proposed, it would be inconsistent with arrays. Let me give three variants: A) as chosen by the Java developers: Object[] array; for(Object o : array) … Read more

Why can’t you have multiple interfaces in a bounded wildcard generic?

Interestingly, interface java.lang.reflect.WildcardType looks like it supports both upper bounds and lower bounds for a wildcard arg; and each can contain multiple bounds Type[] getUpperBounds(); Type[] getLowerBounds(); This is way beyond what the language allows. There’s a hidden comment in the source code // one or many? Up to language spec; currently only one, but … Read more

Which classes cannot be subclassed?

There seems to be two reasons for a class to be “final” in Python. 1. Violation of Class Invariant Classes that follow Singleton pattern have an invariant that there’s a limited (pre-determined) number of instances. Any violation of this invariant in a subclass will be inconsistent with the class’ intent, and would not work correctly. … Read more

What’s the difference between __builtin__ and __builtins__?

Straight from the python documentation: http://docs.python.org/reference/executionmodel.html By default, when in the __main__ module, __builtins__ is the built-in module __builtin__ (note: no ‘s’); when in any other module, __builtins__ is an alias for the dictionary of the __builtin__ module itself. __builtins__ can be set to a user-created dictionary to create a weak form of restricted execution. … Read more