Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback applyOn with Kotlin #588

Closed
Claxtastic opened this issue Dec 14, 2020 · 3 comments
Closed

Fallback applyOn with Kotlin #588

Claxtastic opened this issue Dec 14, 2020 · 3 comments

Comments

@Claxtastic
Copy link

When I use the applyOn parameter for @fallback in Kotlin:
@Fallback(fallbackMethod = "fallbackSaveCallEventBatch", applyOn = { SQLException::class })

I get two errors:
Annotation argument must be compile-time constant.
Type mismatch: inferred type is () -> KClass<SQLException> but Array<KClass<out Throwable!>> was expected.

Is there a correct way to do this in Kotlin, or would something have to be fixed?

@Azquelt
Copy link
Member

Azquelt commented Dec 14, 2020

The error makes it look like it's complaining that it's getting a lambda when it's expecting an array. I'm not too familiar with Kotlin, but this doc section Arrays as annotation parameters suggests that the syntax should be:

Kotlin 1.2+

@Fallback(fallbackMethod = "fallbackSaveCallEventBatch", applyOn = [ SQLException::class ])

Older versions

@Fallback(fallbackMethod = "fallbackSaveCallEventBatch", applyOn = arrayOf(SQLException::class))

@Claxtastic
Copy link
Author

The error makes it look like it's complaining that it's getting a lambda when it's expecting an array. I'm not too familiar with Kotlin, but this doc section Arrays as annotation parameters suggests that the syntax should be:

Kotlin 1.2+

@Fallback(fallbackMethod = "fallbackSaveCallEventBatch", applyOn = [ SQLException::class ])

Older versions

@Fallback(fallbackMethod = "fallbackSaveCallEventBatch", applyOn = arrayOf(SQLException::class))

Oh perfect, that works. Thanks for clearing that up.

@Azquelt
Copy link
Member

Azquelt commented Dec 14, 2020

Happy to hear that 😃

@Azquelt Azquelt closed this as completed Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants