How long can a String property be in Kotlin?

I created a simple Base64Imageshelper class that contains this body:

companion object{
  val ABSTRACT_COLORS = "[image encoded in base64]"
}

ABSTRACT_COLORS - actually a string having 570438 characters.

At compile time, I got:

org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Failed to generate property ABSTRACT_COLORS
...
...
The root cause was thrown at: ByteVector.java:213 at org.jetbrains.kotlin.codegen.MemberCodegen.genFunctionOrProperty(MemberCodegen.java:205)
Caused by: java.lang.IllegalArgumentException

I thought I could store 2147483647 (2 31 - 1) characters in a string.

Why is this?

I posted this snapshot below.
You can use this tool to generate base64.

Hint: editing this class or compiling a project freezes Android Studio.
I would use a small editor for editing and a terminal to compile it.

enter image description here

+4
1

@mfulton26, - . , Kotlin.

src/main/resources String, ByteArray.

, src/main/resources/abstract-colors.txt, :

val ABSTRACT_COLORS = javaClass.getResourceAsStream("/abstract-colors.txt")
                               .bufferedReader().use { it.readText() }

base64, ByteArray.

val ABSTRACT_COLORS = javaClass.getResourceAsStream("/abstract-colors.jpg")
                               .use { it.readBytes() }
+4

Source: https://habr.com/ru/post/1655068/


All Articles