xxfast
05/20/2022, 1:43 PMoverride
keyword? Do we really need it?xxfast
05/20/2022, 1:44 PM‘registration’ hides member of supertype ‘Vehicle’ and needs ‘override’ modifierCouldn’t the compiler just assume it is
override
by default? If not, I don’t understand why do we need this ceremonyxxfast
05/20/2022, 1:46 PMabstract
feels very verbose too sometimes.
Property must be initialized or be abstractin a context of a sealed class, couldn’t the compiler assume it is
abstract
by default?Rob Elliot
05/20/2022, 1:47 PMpublic boolean equals(Foo foo)
and think you have overridden equals when you haven't.Rob Elliot
05/20/2022, 1:49 PM@Overrides
specifically to help with that issue, and Scala also added an override
keyword. My impression is it's fairly widely accepted that it's a Good Thing.xxfast
05/20/2022, 1:49 PMb) failing to override when you meant to do so.wouldn’t the compiler catch that for you?
Rob Elliot
05/20/2022, 1:51 PMequals
. Remember there are open class
as well as `abstract`/`sealed`.Rob Elliot
05/20/2022, 1:58 PMabstract
implicit on an abstract method on an abstract class. Requiring abstract
feels a bit more arbitrary, particularly as both abstract classes and interfaces have methods with and without implementation, and interfaces don't require the abstract
keyword (or Java's default
one). I'd be interested in the reasoning for that.hfhbd
05/20/2022, 2:00 PM@Override
annotated dead function in your code baisEndre Deak
05/20/2022, 2:44 PMinterface Foo {
fun foo()
fun bar() { print("hello bar") }
}
class FooImpl() : Foo {
// this doesn't override anything, but implements it
// yet, we define this as an override...
override fun foo() { print("hello") }
// this actually overrides the behaviour of Foo.bar()
override fun bar() { print("hello fooimpl") }
}
Rob Elliot
05/20/2022, 2:46 PMoverride
means "implements or overrides". The important bit is that it allows the compiler to guarantee that the signature is defined on a supertype (and its absence allows the compiler to guarantee that the signature is not defined on a supertype). Is there a better short term that conveys that?Endre Deak
05/20/2022, 2:56 PMKlitos Kyriacou
05/23/2022, 1:26 PMinterface Ia {
fun foo()
}
interface Ib {
fun foo()
}
class C : Ia, Ib {
override fun Ia.foo() { // Not valid Kotlin
println("a")
}
override fun Ib.foo() { // Not valid Kotlin
println("b")
}
}
Kotlin inherits Java's behaviour with respect to interfaces. This means that we can only implement two interfaces with the same-named function if that function has equivalent meaning between the two interfaces. Sometimes, two interfaces can have two functions that have a totally different intention but their names match purely by coincidence. C# allows us to write different implementations for each such function. In Kotlin, we need to do it in a roundabout way, e.g. by inserting an adaptor interface between one of the interfaces and the implementing class.ephemient
05/25/2022, 1:43 AMephemient
05/25/2022, 1:45 AM