Skip to content

Instantly share code, notes, and snippets.

@wyattbiker
Last active May 3, 2019 21:13
Show Gist options
  • Save wyattbiker/cfaab6b2868d28974ac694790542bb8b to your computer and use it in GitHub Desktop.
Save wyattbiker/cfaab6b2868d28974ac694790542bb8b to your computer and use it in GitHub Desktop.
Generics example
// T is meant to be a Type
// E is meant to be an Element (List<E>: a list of Elements)
// K is Key (in a Map<K, V>)
// V is Value (as a return value or mapped value)
class CacheItem<T, V> {
T itemToCache;
V amountToCache;
CacheItem(T this.itemToCache, V this.amountToCache);
T get detail => itemToCache;
set detail(T v) => itemToCache = v;
}
void main() {
var cached = CacheItem("ABC", 10);
print(cached.detail);
cached.detail = "XYZ";
print(cached.detail);
print(cached.runtimeType);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment