[ ](https://kotlinlang.org) [ v1.9.23
](https://github.com/JetBrains/kotlin/releases/tag/v1.9.23)

  * Solutions 
    * [ Multiplatform ](/lp/mobile/)
    * [ Server-side ](/lp/server-side/)
    * [ Data science ](/docs/data-science-overview.html)
    * [ Android ](/docs/android-overview.html)
  * [ Docs ](/docs/home.html)
  * [ Community ](/community/)
  * [ Teach ](/education/)
  * Play 
    * [ Playground ](https://play.kotlinlang.org/)
    * [ Examples ](https://play.kotlinlang.org/byExample)
    * [ Koans ](https://play.kotlinlang.org/koans)

[ â Docs ](/docs/home.html)

[ kotlin-stdlib ](../../index.html) / [ kotlin.properties ](../index.html) / [
Delegates ](index.html) / [ vetoable ](./vetoable.html)

#  vetoable

Common

JVM

JS

Native

1.0

` inline  fun  < T  > vetoable  (  
Â Â Â Â  initialValue  :  Â  T  ,  
Â Â Â Â  crossinline  onChange  :  Â  (  property  :  Â [ KProperty
](../../kotlin.reflect/-k-property/index.html) < *  > ,  Â  oldValue  :  Â  T
,  Â  newValue  :  Â  T  )  Â  -> Â  Boolean  
)  :  [ ReadWriteProperty  ](../-read-write-property/index.html) < Any  ?  ,
Â  T  > `  
[ (source)
](https://github.com/JetBrains/kotlin/tree/0938b46726b9c6938df309098316ce741815bb55/libraries/stdlib/src/kotlin/properties/Delegates.kt#L49)

Returns a property delegate for a read/write property that calls a specified
callback function when changed, allowing the callback to veto the
modification.

    
    
    import kotlin.properties.Delegates
    
    import kotlin.test.*
    
    fun main(args: Array<String>) {
    //sampleStart
    var max: Int by Delegates.vetoable(0) { property, oldValue, newValue ->
        newValue > oldValue
    }
    
    println(max) // 0
    
    max = 10
    println(max) // 10
    
    max = 5
    println(max) // 10
    //sampleEnd
    }
    
    
    import kotlin.properties.Delegates
    
    import kotlin.test.*
    
    fun main(args: Array<String>) {
    //sampleStart
    var max: Int by Delegates.vetoable(0) { property, oldValue, newValue ->
        if (newValue > oldValue) true else throw IllegalArgumentException("New value must be larger than old value.")
    }
    
    println(max) // 0
    
    max = 10
    println(max) // 10
    
    // max = 5 // will fail with IllegalArgumentException
    //sampleEnd
    }

###  Parameters

` initialValue ` \- the initial value of the property.

` onChange ` \- the callback which is called before a change to the property
value is attempted. The value of the property hasn't been changed yet, when
this callback is invoked. If the callback returns ` true ` the value of the
property is being set to the new value, and if the callback returns ` false `
the new value is discarded and the property remains its old value.

Stay in touch:

[ ](https://github.com/JetBrains/kotlin "Kotlin on GitHub") [
](https://twitter.com/kotlin "Kotlin on Twitter") [
](https://surveys.jetbrains.com/s3/kotlin-slack-sign-up "Kotlin Slack") [
](https://www.reddit.com/r/Kotlin/ "Kotlin on Reddit") [
](https://stackoverflow.com/questions/tagged/kotlin "Kotlin on Stack
Overflow") [ ](https://www.youtube.com/channel/UCP7uiEZIqci43m22KDl0sNw
"Kotlin on YouTube")

  * [ Contributing to Kotlin ](https://kotlinlang.org/docs/contribute.html "Contributing to Kotlin")
  * [ Releases ](https://kotlinlang.org/docs/releases.html "Releases")
  * [ Press Kit ](https://kotlinlang.org/assets/kotlin-media-kit.pdf "Press Kit")
  * [ Security ](https://kotlinlang.org/docs/security.html "Security")
  * [ Blog ](https://blog.jetbrains.com/kotlin/ "Blog")
  * [ Issue Tracker ](https://youtrack.jetbrains.com/issues/KT "Issue Tracker")
  * [ Brand assets ](https://resources.jetbrains.com/storage/products/kotlin/docs/kotlin_logos.zip "Brand assets")
  * [ Careers ](https://www.jetbrains.com/careers/jobs/?team=Kotlin "Careers")

[ ](https://jetbrains.com)

Supported and developed byÂ [ JetBrains ](https://www.jetbrains.com/) .

Kotlinâ¢ isÂ protected under the  [ KotlinÂ Foundation
](https://kotlin