https://kotlinlang.org logo
#announcements
Title
# announcements
x

XQDD

09/11/2019, 10:37 AM
Any idea for abstraction CaptchaType? I do it this way because the annotation parameter only receive const value( compile-time constant )
m

Matteo Mirk

09/11/2019, 10:39 AM
Are you asking for an advice on how to model a common type for PhoneCaptchaType and ImgCaptchaType?
x

XQDD

09/11/2019, 10:40 AM
Yeah, or other elegant ways
image.png
image.png
🙄 1
m

Matteo Mirk

09/11/2019, 10:56 AM
depending on what you want to achieve, you could get away with this for example:
Copy code
abstract class CaptchaType {
    open val allowableValues = ""
    val allowableValueList: List<String>
        get() = allowableValues.split(",")
}

object PhoneCaptchaType : CaptchaType() {
    const val MERCHANT_LOGIN = "PHONE_CAPTCHA_MERCHANT_LOGIN"
    const val ADMIN_FORGET_PASS = "PHONE_CAPTCHA_ADMIN_FORGET_PASS"
    override val allowableValues = "$MERCHANT_LOGIN,$ADMIN_FORGET_PASS"
}
so your objects will have initialization logic factored in common. Is that what you wanted?
x

XQDD

09/11/2019, 11:06 AM
no, allowableValuees isn't compile constant and can't used as annotation parameter
m

Matteo Mirk

09/11/2019, 11:10 AM
okay got it, can’t think of an alternative right now sorry
x

XQDD

09/11/2019, 11:11 AM
I also think so, thanks
m

Matteo Mirk

09/11/2019, 11:15 AM
Maybe you could drop the List property and just use
ImgCaptchaType.allowableValues.contains(scope)
in the controller
that way your objects will have all compile constants
x

XQDD

09/11/2019, 11:20 AM
yeah, got it
👍 1
No, there is a big bug, any letter will pass
m

Matteo Mirk

09/16/2019, 9:30 AM
you mean that
contains(scope)
will pass for any string value?
x

XQDD

09/17/2019, 3:12 PM
yeah, I change it back