From 0d9b50eca28437fead527544bc893a197a60f199 Mon Sep 17 00:00:00 2001 From: John Messerly Date: Thu, 21 Jan 2016 17:09:35 -0800 Subject: [PATCH] fixes #419, clarify docs around /*=T*/ Adds an example and some text to show an alternate usage of /*=T*/ form, where it provides another named type to use for non-strong mode tools. --- pkg/dev_compiler/GENERIC_METHODS.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/dev_compiler/GENERIC_METHODS.md b/pkg/dev_compiler/GENERIC_METHODS.md index 1cc13ae89621..c51b30943cd0 100644 --- a/pkg/dev_compiler/GENERIC_METHODS.md +++ b/pkg/dev_compiler/GENERIC_METHODS.md @@ -84,6 +84,16 @@ This can be written more concisely by leaving off the `dynamic`. /*=S*/ foo/**/(/*=S*/ x) {return x;} ``` +You can also put a type to the left of the `/*=T/`. This type will be used +for all non-strong mode tools. For example: + +```dart +// This method works with `int`, `double`, or `num`. The return type will +// match the type of the parameters. +num/*=T*/ pickAtRandom/**/(num/*=T*/ x, num/*=T*/ y) { ... } +``` + + Note that the generic parameter is in scope in the return type of the function, in the argument list of the function, and in the body of the function. When declaring local variables and parameters, you can also use the `/*=T*/` syntax with `var`.