@@ -840,19 +840,19 @@ may be useful when considering future extensions to the Python type system.
840840C++
841841---
842842
843- C++ uses angle brackets in combination with keywords " template" and
844- " typename" to declare type parameters. It uses angle brackets for
843+ C++ uses angle brackets in combination with keywords `` template `` and
844+ `` typename `` to declare type parameters. It uses angle brackets for
845845specialization.
846846
847847C++20 introduced the notion of generalized constraints, which can act
848848like protocols in Python. A collection of constraints can be defined in
849- a named entity called a " concept" .
849+ a named entity called a `` concept `` .
850850
851851Variance is not explicitly specified, but constraints can enforce variance.
852852
853- A default type argument can be specified using the "=" operator.
853+ A default type argument can be specified using the `` = `` operator.
854854
855- ::
855+ .. code-block :: c++
856856
857857 // Generic class
858858 template <typename>
897897
898898Java uses angle brackets to declare type parameters and for specialization.
899899By default, type parameters are invariant.
900- The " extends" keyword is used to specify an upper bound. The " super" keyword
900+ The `` extends `` keyword is used to specify an upper bound. The `` super `` keyword
901901is used to specify a contravariant bound.
902902
903903Java uses use-site variance. The compiler places limits on which methods and
@@ -906,7 +906,7 @@ not specified explicitly.
906906
907907Java provides no way to specify a default type argument.
908908
909- ::
909+ .. code-block :: java
910910
911911 // Generic class
912912 public class ClassA <T> {
923923--
924924
925925C# uses angle brackets to declare type parameters and for specialization.
926- The " where" keyword and a colon is used to specify the bound for a type
926+ The `` where `` keyword and a colon is used to specify the bound for a type
927927parameter.
928928
929- C# uses declaration-site variance using the keywords "in" and " out" for
929+ C# uses declaration-site variance using the keywords `` in `` and `` out `` for
930930contravariance and covariance, respectively. By default, type parameters are
931931invariant.
932932
933933C# provides no way to specify a default type argument.
934934
935- ::
935+ .. code-block :: c#
936936
937937 // Generic class with bounds on type parameters
938938 public class ClassA <S , T >
@@ -955,21 +955,21 @@ TypeScript
955955----------
956956
957957TypeScript uses angle brackets to declare type parameters and for
958- specialization. The " extends" keyword is used to specify a bound. It can be
959- combined with other type operators such as " keyof" .
958+ specialization. The `` extends `` keyword is used to specify a bound. It can be
959+ combined with other type operators such as `` keyof `` .
960960
961961TypeScript uses declaration-site variance. Variance is inferred from
962962usage, not specified explicitly. TypeScript 4.7 introduced the ability
963- to specify variance using "in" and " out" keywords. This was added to handle
963+ to specify variance using `` in `` and `` out `` keywords. This was added to handle
964964extremely complex types where inference of variance was expensive,
965965yet the maintainers state that is useful for increasing readability.
966966
967- A default type argument can be specified using the "=" operator.
967+ A default type argument can be specified using the `` = `` operator.
968968
969- TypeScript supports the " type" keyword to declare a type alias, and this
969+ TypeScript supports the `` type `` keyword to declare a type alias, and this
970970syntax supports generics.
971971
972- ::
972+ .. code-block :: typescript
973973
974974 // Generic interface
975975 interface InterfaceA <S , T extends SomeInterface1 > {
@@ -996,19 +996,19 @@ Scala
996996-----
997997
998998In Scala, square brackets are used to declare type parameters. Square
999- brackets are also used for specialization. The "<:" and ">:" operators
999+ brackets are also used for specialization. The `` <: `` and `` >: `` operators
10001000are used to specify upper and lower bounds, respectively.
10011001
10021002Scala uses use-site variance but also allows declaration-site variance
1003- specification. It uses a "+" or "-" prefix operator for covariance and
1003+ specification. It uses a `` + `` or `` - `` prefix operator for covariance and
10041004contravariance, respectively.
10051005
10061006Scala provides no way to specify a default type argument.
10071007
10081008It does support higher-kinded types (type parameters that accept type
10091009type parameters).
10101010
1011- ::
1011+ .. code-block :: scala
10121012
10131013
10141014 // Generic class; type parameter has upper bound
@@ -1041,16 +1041,16 @@ Swift
10411041Swift uses angle brackets to declare type parameters and for specialization.
10421042The upper bound of a type parameter is specified using a colon.
10431043
1044- Swift doesn't support generic variance, all type parameters are invariant.
1044+ Swift doesn't support generic variance; all type parameters are invariant.
10451045
10461046Swift provides no way to specify a default type argument.
10471047
1048- ::
1048+ .. code-block :: swift
10491049
10501050 // Generic class
10511051 class ClassA <T > {
10521052 // Generic method
1053- func method1<X>(val: T) -> S { }
1053+ func method1 <X >(val : T) -> X { }
10541054 }
10551055
10561056 // Type parameter with upper bound constraint
@@ -1065,15 +1065,15 @@ Rust
10651065
10661066Rust uses angle brackets to declare type parameters and for specialization.
10671067The upper bound of a type parameter is specified using a colon. Alternatively
1068- a " where" clause can specify various constraints.
1068+ a `` where `` clause can specify various constraints.
10691069
10701070Rust does not have traditional object oriented inheritance or variance.
10711071Subtyping in Rust is very restricted and occurs only due to variance with
10721072respect to lifetimes.
10731073
1074- A default type argument can be specified using the "=" operator.
1074+ A default type argument can be specified using the `` = `` operator.
10751075
1076- ::
1076+ .. code-block :: rust
10771077
10781078 // Generic class
10791079 struct StructA<T> {
@@ -1102,16 +1102,16 @@ Kotlin
11021102
11031103Kotlin uses angle brackets to declare type parameters and for specialization.
11041104By default, type parameters are invariant. The upper bound of a type is
1105- specified using a colon. Alternatively a "where" clause can specify various
1106- constraints.
1105+ specified using a colon.
1106+ Alternatively, a `` where `` clause can specify various constraints.
11071107
11081108Kotlin supports declaration-site variance where variance of type parameters is
1109- explicitly declared using "in" and " out" keywords. It also supports use-site
1109+ explicitly declared using `` in `` and `` out `` keywords. It also supports use-site
11101110variance which limits which methods and members can be used.
11111111
11121112Kotlin provides no way to specify a default type argument.
11131113
1114- ::
1114+ .. code-block :: kotlin
11151115
11161116 // Generic class
11171117 class ClassA<T>
@@ -1133,10 +1133,10 @@ Julia
11331133-----
11341134
11351135Julia uses curly braces to declare type parameters and for specialization.
1136- The "<:" operator can be used within a " where" clause to declare
1136+ The `` <: `` operator can be used within a `` where `` clause to declare
11371137upper and lower bounds on a type.
11381138
1139- ::
1139+ .. code-block :: julia
11401140
11411141 // Generic struct; type parameter with upper and lower bounds
11421142 struct StructA{T} where Int <: T <: Number
@@ -1153,16 +1153,16 @@ Dart
11531153----
11541154
11551155Dart uses angle brackets to declare type parameters and for specialization.
1156- The upper bound of a type is specified using the " extends" keyword. By default,
1157- type parameters are covariant.
1156+ The upper bound of a type is specified using the `` extends `` keyword.
1157+ By default, type parameters are covariant.
11581158
1159- Dart supports declaration-site variance where variance of type parameters is
1160- explicitly declared using "in", " out" and " inout" keywords. It does not support
1161- use-site variance.
1159+ Dart supports declaration-site variance, where variance of type parameters is
1160+ explicitly declared using `` in ``, `` out `` and `` inout `` keywords.
1161+ It does not support use-site variance.
11621162
11631163Dart provides no way to specify a default type argument.
11641164
1165- ::
1165+ .. code-block :: dart
11661166
11671167 // Generic class
11681168 class ClassA<T> { }
0 commit comments