in scala can write code this.
trait list[t] { def isempty() :boolean def head() : t def tail() : list[t] } class cons[t](val head: t, val tail: list[t]) :list[t] { def isempty = false }
you don't need override tail , head defined, in kotlin had code this.
interface list<t> { fun isempty() :boolean fun head() : t fun tail() : list<t> } class cons<t>(val head: t, val tail: list<t>) :list<t> { override fun isempty() = false override fun head() = head override fun tail() = tail }
my question "is better way write kotlin code? "
you can make head
, tail
properties:
interface list<t> { val head: t val tail: list<t> fun isempty(): boolean } class cons<t>(override val head: t, override val tail: list<t>) : list<t> { override fun isempty() = false }
Comments
Post a Comment