Chris Ruddell
02/23/2021, 8:18 PM?
notation instead of force-unwrapping (!!
) everything. I understand the force-unwrapping allows it to be more in a state where it can compile, but I assume most of us go through and replace all those with optionals anyway to ensure null safety. If there is a way of changing that default behavior, please let me know.Alexey Belkov [JB]
03/10/2021, 11:18 AMChris Ruddell
03/11/2021, 12:53 PMpublic class Animal {
private Dog dog;
void adoptDog() {
dog = new Dog();
}
void groomDog() {
dog.hairColor = "";
dog.bark();
}
static class Dog extends Animal {
private String hairColor;
void bark() {
}
}
}
Chris Ruddell
03/11/2021, 12:56 PMclass Animal {
private var dog: Dog? = null
fun adoptDog() {
dog = Dog()
}
fun groomDog() {
dog!!.hairColor = ""
dog!!.bark()
}
internal class Dog : Animal() {
private val hairColor: String? = null
fun bark() {}
}
}
In addition to the dog
variable being forced unwrapped, it won’t even compile because it has marked hairColor
as a val
. I understand it’s not perfect and expect to go over the code after conversion, but force-unwrapping seems like a bad default option compared to simply calling dog?.hairColor = ""
Alexey Belkov [JB]
03/23/2021, 1:26 PMChris Ruddell
03/23/2021, 1:31 PM