Inheritance – Why is this class considered to be the ultimate?

I tried to inherit the following type, but the compiler says it is final.

class Dice(private var side: Int)
{
constructor(D: DiceTypesK): this(D.value) {}
}

class ExplodedDice(private val D: DiceTypesK): Dice (D)
// ^^^^ this class is final and
// can not be inherited from

Why my type is final because I don’t plan to do it ?

In Kotlin, unlike Java and C#, all classes are final by default, unless Clearly marked as open. This is the content of the docs:

The open annotation on a class is the opposite of Java’s final: it allows others to inherit from this class. By default, all classes in Kotlin are final, which corresponds to 07001, Item 17: Design and document for inheritance or else prohibit it.

The solution is just to mark your class as an open class Dice.

In addition, please pay attention to the limitations on data classes inheritance: they can neither be opened nor Extend another class.

I tried to inherit the following type, but the compiler says it is final.

< pre>class Dice(private var side: Int)
{
constructor(D: DiceTypesK): this(D.value) {}
}

class ExplodedDice (private val D: DiceTypesK): Dice(D)
// ^^^^ this class is final and
// can not be inherited from

Why is my type Ultimately, because I don’t plan to do this?

In Kotlin, unlike Java and C#, all classes are final by default, unless explicitly marked as open. This is the content of the docs:

The open annotation on a class is the opposite of Java’s final: it allows others to inherit from this class. By default, all classes in Kotlin are final, which corresponds to 07001, Item 17: Design and document for inheritance or else prohibit it.

The solution is just to The classes are marked as open class Dice.

In addition, please note that the limitations on data classes are inherited: they can neither be opened nor extended by another class.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2826 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.