जो मैं करने की कोशिश कर रहा हूं वह कक्षा की एक विधि को सजाने वाला है।
कोई विचार क्यों कोटलिन ने Derived
को अंतिम रूप में परिभाषित किया? क्या Derived
के लिए अंतिम नहीं होने का कोई तरीका है, इसलिए मैं इसका वारिस कर सकता हूं?
जावा:
new Derived(new BaseImpl(10)) { // Getting the error on this line: `Cannot inherit from final 'Derived'`
};
Kotlin: यहाँ से
interface Base {
fun print()
}
class BaseImpl(val x: Int) : Base {
override fun print() { print(x) }
}
class Derived(b: Base) : Base by b
* उदाहरण: https://kotlinlang.org/docs/reference/delegation.html