Last active
May 3, 2019 21:13
-
-
Save wyattbiker/cfaab6b2868d28974ac694790542bb8b to your computer and use it in GitHub Desktop.
Generics example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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