Luís Soares
Luís Soares

Reputation: 6222

How to avoid or fix Kotlin warning related with Int vs Integer

I have a Spring Boot 2.0.0 / Kotlin / Gradle project. I have a warning while injecting integers. I know the reason but don't know the fix. Is there a better way to inject these @Values? Thanks

Warning:

\src\main\kotlin\com\tech\stands\PicturesDownloader.kt: (22, 31): This class shouldn't be used in Kotlin. Use kotlin.Int instead.

Code:

abstract class PicturesDownloader {

    @Value("\${cache.adpics.concurrent}")
    lateinit var MAX_CONCURRENT: Integer
    @Value("\${cache.adpics.max}")
    lateinit var MAX_AD_PICS: Integer
}

If there's no way to fix, is there way to suppress it?

Upvotes: 3

Views: 1337

Answers (1)

Zoe - Save the data dump
Zoe - Save the data dump

Reputation: 28268

If you want to suppress it, you can use this annotation:

@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")

I'm not familiar with Spring Boot and the value injection system, so I'm not sure if this will work. Set the value to 0, use Int and remove lateinit. As it's still a var, it can still be set after creation, meaning the value injection should be able to set it once the class is created.

@Value("\${cache.adpics.concurrent}")
var MAX_CONCURRENT: Int = 0

Upvotes: 9

Related Questions