In other words, we’ve declared the three variables in the raw type.įor simplicity, we’ll use unit test assertions to verify if we get the expected type. It’s worth mentioning that Kotlin’s Any is pretty similar to Java’s Object, which means it’s the supertype of all other classes. We should note that we’ve declared the three variables using the same type: Any. Private val myPlayer: Any = Player("Jackson", 42, 100)Īs we can see, we’ve created three variables: one Int, one String, and one Player. you can checkout package kotlin.reflect in-order to take a closer look. So they created the star projection so you could have any type to a list or whatever that you don't know the type yet. Private val myString: Any = "I am a string" Every Kotlin class has Any as a superclass by kotlin own definitions. Next, let’s create some variables: private val myInt: Any = 42 Moreover, the Player class inherits the Person class and implements the Ranking interface. Open class Person(val name: String, val age: Int)Ĭlass Player(name: String, age: Int, val numberOfWins: Int) : Person(name, age), RankingĪs the code above shows, in the package, we’ve defined a Person class, a Ranking interface, and a Player class.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |