@@ -914,6 +914,7 @@ Java provides no way to specify a default type argument.
914
914
915
915
// Generic method
916
916
public <S extends Number > void method1 (S value ) { }
917
+
917
918
// Use site variance
918
919
public void method1 (ClassA<? super Integer > value ) { }
919
920
}
@@ -1123,7 +1124,12 @@ Kotlin provides no way to specify a default type argument.
1123
1124
class ClassC<in S, out T>
1124
1125
1125
1126
// Generic function
1126
- fun <T> func1(): T { }
1127
+ fun <T> func1(): T {
1128
+
1129
+ // Use site variance
1130
+ val covariantA: ClassA<out Number>
1131
+ val contravariantA: ClassA<in Number>
1132
+ }
1127
1133
1128
1134
// Generic type alias
1129
1135
typealias TypeAliasFoo<T> = ClassA<T>
@@ -1179,6 +1185,31 @@ Dart provides no way to specify a default type argument.
1179
1185
// Generic type alias
1180
1186
typedef TypeDefFoo<T> = ClassA<T>;
1181
1187
1188
+ Go
1189
+ --
1190
+
1191
+ Go uses square brackets to declare type parameters and for specialization.
1192
+ The upper bound of a type is specified after the name of the parameter, and
1193
+ must always be specified. The keyword ``any `` is used for an unbound type parameter.
1194
+
1195
+ Go doesn't support variance; all type parameters are invariant.
1196
+
1197
+ Go provides no way to specify a default type argument.
1198
+
1199
+ Go does not support generic type aliases.
1200
+
1201
+ .. code-block :: go
1202
+
1203
+ // Generic type without a bound
1204
+ type TypeA[T any] struct {
1205
+ t T
1206
+ }
1207
+
1208
+ // Type parameter with upper bound
1209
+ type TypeB[T SomeType1] struct { }
1210
+
1211
+ // Generic function
1212
+ func func1[T any]() { }
1182
1213
1183
1214
1184
1215
Summary
@@ -1214,6 +1245,8 @@ Summary
1214
1245
| Dart | <> | extends | | | decl | in, out, |
1215
1246
| | | | | | | inout |
1216
1247
+------------+----------+---------+--------+----------+-----------+-----------+
1248
+ | Go | [] | T X | | | n/a | n/a |
1249
+ +------------+----------+---------+--------+----------+-----------+-----------+
1217
1250
| Python | [] | T: X | | | decl | inferred |
1218
1251
| (proposed) | | | | | | |
1219
1252
+------------+----------+---------+--------+----------+-----------+-----------+
0 commit comments