May help to explain this just a bit.
Say I have an abstract class called Page that looks like so:
abstract class Page {
abstract fun title() : String
}
And an interface called Book:
interface Book {
fun write(page: Page)
fun read(title: String) Page
}
My question is how can I use the carat generic syntax to specify that the methods must be used by derived instance of the Page class. Maybe like this:
interface Book<Page> {
fun write(page: Page)
fun read(title: String) : Page
}
class AdventureBookPage(val pageTitle: String, val content: String) : Page() {
override fun title() : String {
return title
}
}
class AdventureBook : Book<AdventureBookPage> {
override fun write(abp: AdventureBookPage) {
// do writing ops
}
override fun read(title: String) : AdventureBookPage {
// do read ops
}
}
Am I misunderstanding how generics work here? Any help would be very much appreciated.