Skip to content

Commit

Permalink
pep695: Fix Kotlin/Java details and add Dart
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Jul 22, 2022
1 parent b1ad370 commit 7f70b1f
Showing 1 changed file with 47 additions and 8 deletions.
55 changes: 47 additions & 8 deletions pep-0695.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -912,6 +913,8 @@ Java provides no way to specify a default type argument.

// Generic method
public <S extends Number> void method1(S value) { }
// Use site variance
public void method1(ClassA<? super Integer> value) { }
}

Expand Down Expand Up @@ -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
Expand All @@ -1116,19 +1120,19 @@ Kotlin provides no way to specify a default type argument.
::

// Generic class
class ClassA<T> { }
class ClassA<T>

// Type parameter with upper bound
class ClassB<T: SomeClass1> { }
class ClassB<T : SomeClass1>

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

// Generic function
fun func1<T>() -> T {}
fun <T> func1(): T { }

// Generic type alias
typealias<T> = ClassA<T>
typealias TypeAliasFoo<T> = ClassA<T>


Julia
Expand All @@ -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<T> { }

// Type parameter with upper bound
class ClassB<T extends SomeClass1> { }

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

// Generic function
T func1<T>() { }

// Generic type alias
typedef TypeDefFoo<T> = ClassA<T>;



Summary
-------
Expand All @@ -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 |
+------------+----------+---------+--------+----------+-----------+-----------+
Expand All @@ -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) | | | | | | |
+------------+----------+---------+--------+----------+-----------+-----------+
Expand Down

0 comments on commit 7f70b1f

Please sign in to comment.