@@ -914,6 +914,7 @@ Java provides no way to specify a default type argument.
914914
915915 // Generic method
916916 public <S extends Number > void method1 (S value ) { }
917+
917918 // Use site variance
918919 public void method1 (ClassA<? super Integer > value ) { }
919920 }
@@ -1123,7 +1124,12 @@ Kotlin provides no way to specify a default type argument.
11231124 class ClassC<in S, out T>
11241125
11251126 // 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+ }
11271133
11281134 // Generic type alias
11291135 typealias TypeAliasFoo<T> = ClassA<T>
@@ -1179,6 +1185,31 @@ Dart provides no way to specify a default type argument.
11791185 // Generic type alias
11801186 typedef TypeDefFoo<T> = ClassA<T>;
11811187
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]() { }
11821213
11831214
11841215 Summary
@@ -1214,6 +1245,8 @@ Summary
12141245| Dart | <> | extends | | | decl | in, out, |
12151246| | | | | | | inout |
12161247+------------+----------+---------+--------+----------+-----------+-----------+
1248+ | Go | [] | T X | | | n/a | n/a |
1249+ +------------+----------+---------+--------+----------+-----------+-----------+
12171250| Python | [] | T: X | | | decl | inferred |
12181251| (proposed) | | | | | | |
12191252+------------+----------+---------+--------+----------+-----------+-----------+
0 commit comments