@@ -840,19 +840,19 @@ may be useful when considering future extensions to the Python type system.
840
840
C++
841
841
---
842
842
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
845
845
specialization.
846
846
847
847
C++20 introduced the notion of generalized constraints, which can act
848
848
like 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 `` .
850
850
851
851
Variance is not explicitly specified, but constraints can enforce variance.
852
852
853
- A default type argument can be specified using the "=" operator.
853
+ A default type argument can be specified using the `` = `` operator.
854
854
855
- ::
855
+ .. code-block :: c++
856
856
857
857
// Generic class
858
858
template <typename>
897
897
898
898
Java uses angle brackets to declare type parameters and for specialization.
899
899
By 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
901
901
is used to specify a contravariant bound.
902
902
903
903
Java uses use-site variance. The compiler places limits on which methods and
@@ -906,7 +906,7 @@ not specified explicitly.
906
906
907
907
Java provides no way to specify a default type argument.
908
908
909
- ::
909
+ .. code-block :: java
910
910
911
911
// Generic class
912
912
public class ClassA <T> {
923
923
--
924
924
925
925
C# 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
927
927
parameter.
928
928
929
929
C# uses declaration-site variance using the keywords "in" and "out" for
@@ -932,7 +932,7 @@ invariant.
932
932
933
933
C# provides no way to specify a default type argument.
934
934
935
- ::
935
+ .. code-block :: c#
936
936
937
937
// Generic class with bounds on type parameters
938
938
public class ClassA <S , T >
@@ -955,21 +955,21 @@ TypeScript
955
955
----------
956
956
957
957
TypeScript 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 `` .
960
960
961
961
TypeScript uses declaration-site variance. Variance is inferred from
962
962
usage, 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
964
964
extremely complex types where inference of variance was expensive,
965
965
yet the maintainers state that is useful for increasing readability.
966
966
967
- A default type argument can be specified using the "=" operator.
967
+ A default type argument can be specified using the `` = `` operator.
968
968
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
970
970
syntax supports generics.
971
971
972
- ::
972
+ .. code-block :: typescript
973
973
974
974
// Generic interface
975
975
interface InterfaceA <S , T extends SomeInterface1 > {
@@ -996,19 +996,19 @@ Scala
996
996
-----
997
997
998
998
In 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
1000
1000
are used to specify upper and lower bounds, respectively.
1001
1001
1002
1002
Scala 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
1004
1004
contravariance, respectively.
1005
1005
1006
1006
Scala provides no way to specify a default type argument.
1007
1007
1008
1008
It does support higher-kinded types (type parameters that accept type
1009
1009
type parameters).
1010
1010
1011
- ::
1011
+ .. code-block :: scala
1012
1012
1013
1013
1014
1014
// Generic class; type parameter has upper bound
@@ -1041,16 +1041,16 @@ Swift
1041
1041
Swift uses angle brackets to declare type parameters and for specialization.
1042
1042
The upper bound of a type parameter is specified using a colon.
1043
1043
1044
- Swift doesn't support generic variance, all type parameters are invariant.
1044
+ Swift doesn't support generic variance; all type parameters are invariant.
1045
1045
1046
1046
Swift provides no way to specify a default type argument.
1047
1047
1048
- ::
1048
+ .. code-block :: swift
1049
1049
1050
1050
// Generic class
1051
1051
class ClassA <T > {
1052
1052
// Generic method
1053
- func method1<X>(val: T) -> S { }
1053
+ func method1 <X >(val : T) -> X { }
1054
1054
}
1055
1055
1056
1056
// Type parameter with upper bound constraint
@@ -1065,15 +1065,15 @@ Rust
1065
1065
1066
1066
Rust uses angle brackets to declare type parameters and for specialization.
1067
1067
The 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.
1069
1069
1070
1070
Rust does not have traditional object oriented inheritance or variance.
1071
1071
Subtyping in Rust is very restricted and occurs only due to variance with
1072
1072
respect to lifetimes.
1073
1073
1074
- A default type argument can be specified using the "=" operator.
1074
+ A default type argument can be specified using the `` = `` operator.
1075
1075
1076
- ::
1076
+ .. code-block :: rust
1077
1077
1078
1078
// Generic class
1079
1079
struct StructA<T> {
@@ -1102,16 +1102,16 @@ Kotlin
1102
1102
1103
1103
Kotlin uses angle brackets to declare type parameters and for specialization.
1104
1104
By 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.
1107
1107
1108
1108
Kotlin 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
1110
1110
variance which limits which methods and members can be used.
1111
1111
1112
1112
Kotlin provides no way to specify a default type argument.
1113
1113
1114
- ::
1114
+ .. code-block :: kotlin
1115
1115
1116
1116
// Generic class
1117
1117
class ClassA<T>
@@ -1133,10 +1133,10 @@ Julia
1133
1133
-----
1134
1134
1135
1135
Julia 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
1137
1137
upper and lower bounds on a type.
1138
1138
1139
- ::
1139
+ .. code-block :: julia
1140
1140
1141
1141
// Generic struct; type parameter with upper and lower bounds
1142
1142
struct StructA{T} where Int <: T <: Number
@@ -1153,16 +1153,16 @@ Dart
1153
1153
-----
1154
1154
1155
1155
Dart 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.
1158
1158
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.
1162
1162
1163
1163
Dart provides no way to specify a default type argument.
1164
1164
1165
- ::
1165
+ .. code-block :: dart
1166
1166
1167
1167
// Generic class
1168
1168
class ClassA<T> { }
0 commit comments