Skip to content

Commit f661b8e

Browse files
committed
pep695: Fix Kotlin/Java details and add Dart
1 parent b1ad370 commit f661b8e

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

pep-0695.rst

+47-8
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,8 @@ Java
896896
----
897897

898898
Java uses angle brackets to declare type parameters and for specialization.
899-
The "extends" keyword is used to specify an upper bound.
899+
The "extends" keyword is used to specify an upper bound. The "super" keyword
900+
is used to specify contravarriant bound
900901

901902
Java uses use-site variance. The compiler places limits on which methods and
902903
members can be accessed based on the use of a generic type. Variance is
@@ -912,6 +913,8 @@ Java provides no way to specify a default type argument.
912913

913914
// Generic method
914915
public <S extends Number> void method1(S value) { }
916+
// Use site variance
917+
public void method1(ClassA<? super Integer> value) { }
915918
}
916919
917920

@@ -1105,7 +1108,8 @@ Kotlin
11051108
------
11061109

11071110
Kotlin uses angle brackets to declare type parameters and for specialization.
1108-
The upper bound of a type is specified using a colon.
1111+
The upper bound of a type is specified using a colon. Alternatively
1112+
a "where" clause can specify various constraints.
11091113

11101114
Kotlin supports declaration-site variance where variance of type parameters is
11111115
explicitly declared using "in" and "out" keywords. It also supports use-site
@@ -1116,19 +1120,19 @@ Kotlin provides no way to specify a default type argument.
11161120
::
11171121

11181122
// Generic class
1119-
class ClassA<T> { }
1123+
class ClassA<T>
11201124

11211125
// Type parameter with upper bound
1122-
class ClassB<T: SomeClass1> { }
1126+
class ClassB<T : SomeClass1>
11231127

11241128
// Contravariant and covariant type parameters
11251129
class ClassC<in S, out T> { }
11261130

11271131
// Generic function
1128-
fun func1<T>() -> T {}
1132+
fun <T> func1(): T { }
11291133

11301134
// Generic type alias
1131-
typealias<T> = ClassA<T>
1135+
typealias TypeAliasFoo<T> = ClassA<T>
11321136

11331137

11341138
Julia
@@ -1151,6 +1155,36 @@ upper and lower bounds on a type.
11511155
// Alternate form of generic function
11521156
function func2(v::Container{T} where T <: Real)
11531157

1158+
Dart
1159+
-----
1160+
1161+
Dart uses angle brackets to declare type parameters and for specialization.
1162+
The upper bound of a type is specified using a colon.
1163+
1164+
Dart supports declaration-site variance where variance of type parameters is
1165+
explicitly declared using "in", "out" and "inout" keywords. It does not support
1166+
use-site variance.
1167+
1168+
Dart provides no way to specify a default type argument.
1169+
1170+
::
1171+
1172+
// Generic class
1173+
class ClassA<T> { }
1174+
1175+
// Type parameter with upper bound
1176+
class ClassB<T extends SomeClass1> { }
1177+
1178+
// Contravariant and covariant type parameters
1179+
class ClassC<in S, out T> { }
1180+
1181+
// Generic function
1182+
T func1<T>() { }
1183+
1184+
// Generic type alias
1185+
typedef TypeDefFoo<T> = ClassA<T>;
1186+
1187+
11541188

11551189
Summary
11561190
-------
@@ -1162,7 +1196,8 @@ Summary
11621196
| C++ | template | n/a | n/a | = | n/a | n/a |
11631197
| | <> | | | | | |
11641198
+------------+----------+---------+--------+----------+-----------+-----------+
1165-
| Java | <> | extends | | | use | inferred |
1199+
| Java | <> | extends | | | use | super, |
1200+
| | | | | | | extends |
11661201
+------------+----------+---------+--------+----------+-----------+-----------+
11671202
| C# | <> | where | | | decl | in, out |
11681203
+------------+----------+---------+--------+----------+-----------+-----------+
@@ -1176,10 +1211,14 @@ Summary
11761211
| Rust | <> | T: X, | | = | decl | inferred, |
11771212
| | | where | | | | explicit |
11781213
+------------+----------+---------+--------+----------+-----------+-----------+
1179-
| Kotlin | <> | T: X | | | use, decl | inferred |
1214+
| Kotlin | <> | T: X, | | | use, decl | in, out |
1215+
| | | where | | | | |
11801216
+------------+----------+---------+--------+----------+-----------+-----------+
11811217
| Julia | {} | T <: X | X <: T | | n/a | n/a |
11821218
+------------+----------+---------+--------+----------+-----------+-----------+
1219+
| Dart | <> | extends | | | decl | in, out, |
1220+
| | | | | | | inout |
1221+
+------------+----------+---------+--------+----------+-----------+-----------+
11831222
| Python | [] | T: X | | | decl | inferred |
11841223
| (proposed) | | | | | | |
11851224
+------------+----------+---------+--------+----------+-----------+-----------+

0 commit comments

Comments
 (0)