Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Unified Diff: pkg/dev_compiler/doc/GENERIC_METHODS.md

Issue 2555803003: Revise the generic methods doc. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/doc/GENERIC_METHODS.md
diff --git a/pkg/dev_compiler/doc/GENERIC_METHODS.md b/pkg/dev_compiler/doc/GENERIC_METHODS.md
index b3c7bbaf93fb0b5d07e00919bd98ee12c187351c..a61748c835a98c6b02193f507dbc37673c870b8a 100644
--- a/pkg/dev_compiler/doc/GENERIC_METHODS.md
+++ b/pkg/dev_compiler/doc/GENERIC_METHODS.md
@@ -1,5 +1,9 @@
# Using Generic Methods
+**Note: For historical reasons, this feature is called "generic methods", but it
+applies equally well to instance methods, static methods, top-level functions,
+local functions, and even lambda expressions.**
+
Initially a [proposal][], generic methods are on their way to being fully
supported in Dart. Here is how to use them.
@@ -110,29 +114,33 @@ almost anywhere you would expect in a generic method.
treated like `dynamic` today. So in this example, `pair`'s reified type at
runtime will be `List<dynamic>` and `set` will be `Set<dynamic>`.
+There are two places you *cannot* use a generic method type parameter. Both are
+because the VM and dart2js don't support reifying generic method type arguments
+yet. Since these expressions wouldn't do what you want, we've temporarily
+defined them to be an error:
+
+* As the right-hand side of an `is` or `is!` expression.
+
+ ```dart
+ testType<T>(object) {
+ print(object is T);
+ // ^-- Error!
+ print(object is! T);
+ // ^-- Error!
+ }
+ ```
+
* As a type literal:
```dart
printType<T>() {
Type t = T;
- // ^-- Here.
+ // ^-- Error!
print(t);
}
```
- Again, note that on the VM and dart2js, this will currently print "dynamic".
-
-The one place you cannot currently use a generic method type parameter is in an
-`is` expression. Since the VM and dart2js don't reify generic method type
-arguments yet, those expressions wouldn't do what you want. Instead, this is
-currently an error:
-
-```dart
-testType<T>(object) {
- print(object is T);
- // ^-- Error!
-}
-```
+Once we have full runtime support for generic methods, these will be allowed.
## Calling generic methods
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698