File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -407,6 +407,26 @@ is not generic but implicitly inherits from ``Iterable[Any]``:
407
407
...
408
408
409
409
410
+ Instantiating generic classes and type erasure
411
+ ----------------------------------------------
412
+
413
+ Generic types like ``List`` or ``Sequence`` cannot be instantiated.
414
+ However, user-defined classes derived from them can be instantiated.
415
+ Given a generic class ``Node[T]`` there are three forms of
416
+ instantiation:
417
+
418
+ * ``x = Node()`` -- the type of x is ``Node[Any]``.
419
+
420
+ * ``x = Node[T]()`` -- the type of x is ``Node[T]``.
421
+
422
+ * ``x = Node[int]()`` -- the type of x is ``Node[int]``.
423
+
424
+ At runtime the type is not preserved, and the observable type of x is
425
+ just ``Node``. This is type erasure and common practice in languages
426
+ with generics (e.g. Java, Typescript).
427
+
428
+
429
+
410
430
Arbitrary generic types as base classes
411
431
---------------------------------------
412
432
You can’t perform that action at this time.
0 commit comments