From 7f70b1ff4193dd1d67d654ca2da9b725de29b919 Mon Sep 17 00:00:00 2001 From: KotlinIsland Date: Fri, 22 Jul 2022 14:50:50 +1000 Subject: [PATCH] pep695: Fix Kotlin/Java details and add Dart --- pep-0695.rst | 55 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/pep-0695.rst b/pep-0695.rst index 85af019f8cc8..1791ce4196af 100644 --- a/pep-0695.rst +++ b/pep-0695.rst @@ -896,7 +896,8 @@ Java ---- Java uses angle brackets to declare type parameters and for specialization. -The "extends" keyword is used to specify an upper bound. +The "extends" keyword is used to specify an upper bound. The "super" keyword +is used to specify a contravariant bound Java uses use-site variance. The compiler places limits on which methods and 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. // Generic method public void method1(S value) { } + // Use site variance + public void method1(ClassA value) { } } @@ -1105,7 +1108,8 @@ Kotlin ------ Kotlin uses angle brackets to declare type parameters and for specialization. -The upper bound of a type is specified using a colon. +The upper bound of a type is specified using a colon. Alternatively +a "where" clause can specify various constraints. Kotlin supports declaration-site variance where variance of type parameters is 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. :: // Generic class - class ClassA { } + class ClassA // Type parameter with upper bound - class ClassB { } + class ClassB // Contravariant and covariant type parameters class ClassC { } // Generic function - fun func1() -> T {} + fun func1(): T { } // Generic type alias - typealias = ClassA + typealias TypeAliasFoo = ClassA Julia @@ -1151,6 +1155,36 @@ upper and lower bounds on a type. // Alternate form of generic function function func2(v::Container{T} where T <: Real) +Dart +----- + +Dart uses angle brackets to declare type parameters and for specialization. +The upper bound of a type is specified using a colon. + +Dart supports declaration-site variance where variance of type parameters is +explicitly declared using "in", "out" and "inout" keywords. It does not support +use-site variance. + +Dart provides no way to specify a default type argument. + +:: + + // Generic class + class ClassA { } + + // Type parameter with upper bound + class ClassB { } + + // Contravariant and covariant type parameters + class ClassC { } + + // Generic function + T func1() { } + + // Generic type alias + typedef TypeDefFoo = ClassA; + + Summary ------- @@ -1162,7 +1196,8 @@ Summary | C++ | template | n/a | n/a | = | n/a | n/a | | | <> | | | | | | +------------+----------+---------+--------+----------+-----------+-----------+ -| Java | <> | extends | | | use | inferred | +| Java | <> | extends | | | use | super, | +| | | | | | | extends | +------------+----------+---------+--------+----------+-----------+-----------+ | C# | <> | where | | | decl | in, out | +------------+----------+---------+--------+----------+-----------+-----------+ @@ -1176,10 +1211,14 @@ Summary | Rust | <> | T: X, | | = | decl | inferred, | | | | where | | | | explicit | +------------+----------+---------+--------+----------+-----------+-----------+ -| Kotlin | <> | T: X | | | use, decl | inferred | +| Kotlin | <> | T: X, | | | use, decl | in, out | +| | | where | | | | | +------------+----------+---------+--------+----------+-----------+-----------+ | Julia | {} | T <: X | X <: T | | n/a | n/a | +------------+----------+---------+--------+----------+-----------+-----------+ +| Dart | <> | extends | | | decl | in, out, | +| | | | | | | inout | ++------------+----------+---------+--------+----------+-----------+-----------+ | Python | [] | T: X | | | decl | inferred | | (proposed) | | | | | | | +------------+----------+---------+--------+----------+-----------+-----------+