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

Side by Side Diff: src/site/_includes/language-tour/generics/index.markdown

Issue 10788006: new site (Closed) Base URL: https://code.google.com/p/dartlang-site/@master
Patch Set: final patch Created 8 years, 5 months 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 unified diff | Download patch
OLDNEW
1 If you look at the API documentation for the basic array type, 1 If you look at the API documentation for the basic array type,
2 [List](http://api.dartlang.org/dart_core/List.html), 2 [List](http://api.dartlang.org/dart_core/List.html),
3 you'll see that the type is actually **List\<E>**. 3 you'll see that the type is actually **List\<E>**.
4 The \<...> notation marks List as a _generic_ 4 The \<...> notation marks List as a _generic_
5 (or _parameterized_) type&mdash;a 5 (or _parameterized_) type&mdash;a
6 type that can declare formal type parameters. 6 type that can declare formal type parameters.
7 7
8 8
9 ### Why use generics? 9 ### Why use generics?
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 For example: 87 For example:
88 88
89 {% highlight dart %} 89 {% highlight dart %}
90 var names = <String>['Seth', 'Kathy', 'Lars']; 90 var names = <String>['Seth', 'Kathy', 'Lars'];
91 var pages = <String>{ // Specify value type: String 91 var pages = <String>{ // Specify value type: String
92 'index.html':'Homepage', // (the key type is implicitly String). 92 'index.html':'Homepage', // (the key type is implicitly String).
93 'robots.txt':'Hints for web robots', 93 'robots.txt':'Hints for web robots',
94 'humans.txt':'We are people, not machines' }; 94 'humans.txt':'We are people, not machines' };
95 {% endhighlight %} 95 {% endhighlight %}
96 96
97 <aside class="note" markdown="1"> 97 <aside>
98 **Note:** 98 <div class="alert alert-info">
99 Map literals always have string _keys_. 99 <strong>Tip:</strong>
100 The type before the brace specifies the type of the map's _values_. 100 Map literals always have string _keys_.
101 The type before the brace specifies the type of the map's _values_.
102 </div>
101 </aside> 103 </aside>
102 104
103 </section> 105 </section>
104 106
105 107
106 <section id="generics-constructors" markdown="1"> 108 <section id="generics-constructors" markdown="1">
107 ### Using constructors 109 ### Using constructors
108 110
109 To specify one or more types when using a constructor, 111 To specify one or more types when using a constructor,
110 put the types in angle brackets 112 put the types in angle brackets
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 145
144 However, the **is** expression 146 However, the **is** expression
145 checks the type of the _collection_ only&mdash;not 147 checks the type of the _collection_ only&mdash;not
146 of the objects inside it. 148 of the objects inside it.
147 In production mode, 149 In production mode,
148 a `List<String>` might have some non-string items in it. 150 a `List<String>` might have some non-string items in it.
149 The solution is to either 151 The solution is to either
150 check each item's type or 152 check each item's type or
151 wrap item-manipulation code in an [exception handler](#exceptions). 153 wrap item-manipulation code in an [exception handler](#exceptions).
152 154
153 <aside class="note" markdown="1"> 155 <aside>
154 **Note:** 156 <div class="alert alert-info">
155 In contrast, 157 <strong>Note:</strong>
156 generics in Java use _erasure_, 158 In contrast,
157 which means that generic type parameters are removed at runtime. 159 generics in Java use _erasure_,
158 In Java, you can test whether an object is a List, 160 which means that generic type parameters are removed at runtime.
159 but you can't test whether it's a List&lt;String>. 161 In Java, you can test whether an object is a List,
162 but you can't test whether it's a <code>List&lt;String&gt;</code>.
163 </div>
160 </aside> 164 </aside>
161 </section> 165 </section>
162 166
163
164 <section id="generics-summary" markdown="1"> 167 <section id="generics-summary" markdown="1">
165 ### Summary of generics 168 ### Summary of generics
166 169
167 For more information about generics, see 170 For more information about generics, see
168 [Optional Types in Dart](http://www.dartlang.org/articles/optional-types/). 171 [Optional Types in Dart](http://www.dartlang.org/articles/optional-types/).
169 </section> 172 </section>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698