Kotlin: single property with multiple setters of different types -


i'm trying build class has property of localdate type has setters accept different types: localdate or string. in case of localdate, value gets assigned directly, in case of string, gets parsed , assigned. in java, need implement 2 overloaded setters handling both of above mentioned cases. have no idea how handle in kotlin. have tried this:

class someexampleclass(var _date: localdate) {     var date = _date         set(value) {             when(value) {                 localdate -> value                 string -> localdate.parse(value)             }         } } 

it doesn't compile. how can resolve such problem?

so if want construct (via constructor), create secondary constructor

someexampleclass(localdate.max) someexampleclass("2007-12-03")  class someexampleclass(var _date: localdate) {     constructor(_date: string) : this(localdate.parse(_date)) } 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -