Android kotlin casting warning

38 Views Asked by At

I am using singleton design pattern but I am getting below casting warning how to resolve it.

Unchecked cast: DownloadManager<*>? to DownloadManager

At Line -

instance as? DownloadManager ?: DownloadManager(

Code

inline fun <reified OfflineContentMeta> DownloadManager() = DownloadManager.createInstance(
)

class DownloadManager<OfflineContentMetaData> private constructor(


) : DownloadProvider {

companion object {

    private var instance: DownloadManager<*>? = null

    const val MSG =
        "Tried to re-init this download manager"

    fun <OfflineContentMeta> createInstance(
       
    ): DownloadManager<OfflineContentMeta>? {
        return if (instance == null) {
            synchronized(this) {
                instance as? DownloadManager<OfflineContentMeta> ?: DownloadManager(
                   
                ).also {
                    instance = it
                }
            }
        } else {
            instance?.let {
                throw Exception(
                    message = MSG,
                )
            }

        }
    }
}

 }
0

There are 0 best solutions below