I’m relatively new to the Kotlin community and found this apparently simple error that I haven’t been able to solve yet:
import com.akuleshov7.ktoml.Toml
import com.akuleshov7.ktoml.source.decodeFromStream
import java.io.File
import java.io.InputStream
class Something <out T> {
private val file = File("file.toml").inputStream()
private val content = Toml.decodeFromStream<T>(file)
}
```kt
Apparently `Toml.decodeFromStream<T>(file)` cannot use the wildcard from the class or it will return the error `Cannot use T as reified type parameter. Use a class instead`
I kind of found a workaround ||a little bit hardcoded tbh|| implementing this function:
```kt
private inline fun <reified R : T> call() {
...
}
Still that forces me to include the type when calling the function and even if it doesn’t I still need to do this in the constructor.
Has anyone found this error before?
I’m starting to think that what I want (Using the class wildcard in the method decodeFromStream) might not be possible in the constructor, o I just want to know if it’s indeed not possible or, if it is, what should I change?
Really hope someone can give me advise on this!
user24962484 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.