I am unsure if it is possible for a kotlin extension to be set like a java object.
In my program I have a java class called Submission
and I wanted to create a kotlin extension of that called categories
- an ArrayList - so I made it like this.
var Submission.categories: ArrayList<String>
get() {
return this.categories
}
set(categories){
this.categories = categories
}
However whenever I try set a category the program just crashes with a stackOverflowError like this:
ERR: stack=java.lang.StackOverflowError: stack size 8MB
at com.....setCategories(Extensions.kt:0)
at com.....setCategories(Extensions.kt:19)
at com.....setCategories(Extensions.kt:19)
at com.....setCategories(Extensions.kt:19)
at com.....setCategories(Extensions.kt:19)
at com.....setCategories(Extensions.kt:19)
This seems like the right syntax for declaring kotlin extensions. So I am really unsure of what direction I ought to go about fixing this in. Perhaps I should really just be using plain old inheritance?
Thanks.