Last active
November 26, 2019 03:54
-
-
Save dandvl/b485cb4be7ff42ae5797ffa3bf2fd259 to your computer and use it in GitHub Desktop.
SealClass
This file contains 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
//All these 4 classes MUST be in the same file | |
sealed class Product | |
data class AlphaProduct (var name: String, var description:String) : Product() | |
data class BetaProduct (var name: String, var description:String) : Product() | |
data class GameProduct (var name: String, var description:String) : Product() | |
var one = AlphaProduct("alpha", "one") | |
var two = BetaProduct("beta", "two") | |
var three = GameProduct("game", "three") | |
var listOfProducts = mutableListOf<Product>() | |
listOfProducts.add(one) | |
listOfProducts.add(two) | |
listOfProducts.add(three) | |
listOfProducts.forEach { product -> | |
if(product is AlphaProduct){ | |
Log.i("test", "${product.name}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment