```val buffer = ByteBuffer.allocate(4450)``` intel...
# getting-started
l
Copy code
val buffer = ByteBuffer.allocate(4450)
intellij says the inferred type of this is
val buffer: (ByteBuffer..ByteBuffer?)
what does that mean? this isn't even valid code when i try to type this out myself. the code compiles fine on my machine, but jitpack.io fails because of a type mismatch. what is going on here?
m
ByteBuffer allocation is probably Java Interrop, which is either nullable or not. You'll probably have to handle something like:
val buffer = ByteBuffer.allocate(4450)!!
or
val buffer = ByteBuffer.allocate(4450) ?: return someFailedReturn
can't the type just be ByteBuffer?
l
shouldnt it be
ByteBuffer!
then ?
i updated to kotlin 1.6.20 which just released, and now it does show
ByteBuffer!
as expected. however jitpack still fails with
Type mismatch: inferred type is Buffer! but ByteBuffer was expected
i am so confused
s
Inferred type is
Buffer
? That sounds like something from a different library entirely. Is that a typo or is that the exact wording of the error message?
l
its copypasted from the log. i was wondering about this too
s
Are you using any other libraries like ktor or okio?
l
i am using ktor, but i already double checked that i'm not using the wrong type. its definitely
java.nio.ByteBuffer
everywhere
e
you are probably running into a Java version difference somewhere
e.g.
ByteBuffer.clear()
is a method of its
Buffer
supertype on Java 8- and so returns a
Buffer
, while there is a specific overload on Java 9+ that returns a
ByteBuffer
instead
👏 1
blob think smart 1
it's a pain, but unrelated to Kotlin and whatever you're seeing in your IDE
d
T!
is a short form of
(T..T?)
type
l
@ephemient ah yes that seems to be it. thanks! @dmitriy.novozhilov thats good to know, can you elaboraote or point me to a resource where i can learn more about this?
e
it's internal notation for lower and upper bounds, it's not something you can type yourself (well, not that you can type the platform type yourself either)
1
d
l
thanks
e
https://youtrack.jetbrains.com/issue/KTOR-1398 btw. there's supposed to be a
-Xjdk-release
coming in Kotlin 1.7, similar to Java's
--release
flag, to make it a bit less painful to target older JDKs when building with a newer one'