@@ -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
}
@@ -1133,7 +1134,12 @@ Kotlin provides no way to specify a default type argument.
1133
1134
class ClassC<in S, out T>
1134
1135
1135
1136
// Generic function
1136
- fun <T> func1(): T { }
1137
+ fun <T> func1(): T {
1138
+
1139
+ // Use site variance
1140
+ val covariantA: ClassA<out Number>
1141
+ val contravariantA: ClassA<in Number>
1142
+ }
1137
1143
1138
1144
// Generic type alias
1139
1145
typealias TypeAliasFoo<T> = ClassA<T>
@@ -1189,6 +1195,31 @@ Dart provides no way to specify a default type argument.
1189
1195
// Generic type alias
1190
1196
typedef TypeDefFoo<T> = ClassA<T>;
1191
1197
1198
+ Go
1199
+ --
1200
+
1201
+ Go uses square brackets to declare type parameters and for specialization.
1202
+ The upper bound of a type is specified after the name of the parameter, and
1203
+ must always be specified. The keyword ``any `` is used for an unbound type parameter.
1204
+
1205
+ Go doesn't support variance; all type parameters are invariant.
1206
+
1207
+ Go provides no way to specify a default type argument.
1208
+
1209
+ Go does not support generic type aliases.
1210
+
1211
+ .. code-block :: go
1212
+
1213
+ // Generic type without a bound
1214
+ type TypeA[T any] struct {
1215
+ t T
1216
+ }
1217
+
1218
+ // Type parameter with upper bound
1219
+ type TypeB[T SomeType1] struct { }
1220
+
1221
+ // Generic function
1222
+ func func1[T any]() { }
1192
1223
1193
1224
1194
1225
Summary
@@ -1224,6 +1255,8 @@ Summary
1224
1255
| Dart | <> | extends | | | decl | in, out, |
1225
1256
| | | | | | | inout |
1226
1257
+------------+----------+---------+--------+----------+-----------+-----------+
1258
+ | Go | [] | T X | | | n/a | n/a |
1259
+ +------------+----------+---------+--------+----------+-----------+-----------+
1227
1260
| Python | [] | T: X | | | decl | inferred |
1228
1261
| (proposed) | | | | | | |
1229
1262
+------------+----------+---------+--------+----------+-----------+-----------+
0 commit comments