Hi Everyone, Is there any way to expect static fun...
# multiplatform
s
Hi Everyone, Is there any way to expect static function of java with typealias: This what I'm trying todo common:
Copy code
expect abstract class CharBuffer : Buffer {
  companion object {
    @JvmStatic
    fun wrap(charArray: CharArray): CharBuffer
  }
}
jvm:
Copy code
actual typealias CharBuffer = java.nio.CharBuffer
wrap is static function of java.nio.CharBuffer with this I'm getting error:
Actual class 'CharBuffer' has no corresponding members for expected class members:  public expect companion object
f
the actual of a alias, must be of the same type
Class/class object/object ...
s
@François but what is the solution for static functions? We don't have static keyword in kotlin
f
are you using okio for the Buffer class? it should be compatible with the jvm
s
No its from java.nio.Buffer and java.nio.CharBuffer I'm creating Multiplatform implementation for it. java.nio.CharBuffer have station function
wrap
and I don't know how to expect it. For now i created factory class to use it like this:
Copy code
actual object CharBufferFactory {
    actual fun wrap(
        charArray: CharArray,
        offset: Int,
        length: Int
    ): CharBuffer {
        return java.nio.CharBuffer.wrap(charArray, offset, length)
    }

    actual fun wrap(
        charSequence: CharSequence,
        offset: Int,
        length: Int
    ): CharBuffer {
        return java.nio.CharBuffer.wrap(charSequence, offset, length)
    }

    actual fun allocate(capacity: Int): CharBuffer {
        return java.nio.CharBuffer.allocate(capacity)
    }
}
f
Yes, I think it’s the good way. You couldn’t expect/actual CharBuffer itself.