Programming in Dart: Functions & Closures

Jun 21 2022 · Dart 2.16, Flutter, DartPad

Part 2: Learn Anonymous Functions & Closures

16. Learn Generic Functions

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 15. Understand Generics Next episode: 17. Challenge: Write a Generic Function

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In the last episode, you were introduced to generics. You saw how the help you write code once that can be used for a lot of different types. Now, it’s time to actually write some generic code. One big thing to keep in mind - generic code must be, er, generic. Meaning, you must write code in a way that ensures that the type is able to be used in way you want to use it.

List<T>
List<T> toList<T>
List<T> toList<T>(T item1, T item2, T item3) {

}
return [item1, item2, item3];
var scoreList = toList<int>(58, 94, 78);
var scoreList = toList(58, 94, 78);
var nameList = toList('Brian', 'Larry', 'Curly');
print(scoreList);
print(nameList);