Kotlin Bites Code

Disclosure: AI-assisted content — consult with an organic-developer.

When building low-level libraries for the JVM — especially those that interact with JNI, rendering engines, or MethodHandles — the exact bytecode emitted matters. Recently I hit a limitation in Kotlin that reminded me why the JVM world still needs Java for certain things.


Where Kotlin Emits Different Bytecode than Java

Here are the main areas where Kotlin’s generated bytecode diverges from Java’s, and why that matters.

AreaJavaKotlinTakeaway
Signature-polymorphic callsEmits correct signature for MethodHandle.invokeExactFalls back to (Object[])Object, causing mismatchesKeep these calls in Java
Default parametersNo defaults → use overloadsGenerates synthetic $default methods with bitmaskAvoid defaults in public APIs for Java clients
Companion objects / @JvmStaticTrue static methodsMethods live in $Companion unless annotatedUse @JvmStatic or plain Java for static APIs
Internal visibilityPackage-private supportedinternal compiles to public + metadataDon’t rely on internal for cross-language encapsulation
SAM interfacesAny functional interface = lambdaOnly fun interface supports SAM; lambdas may create synthetic classesDefine callbacks in Java for performance
NullabilityAll references nullableAnnotations encode nullability, JVM doesn’t enforceExplicit null checks needed in low-level code
Suspend functions / coroutinesN/ACompiles to (Arg, Continuation) → ObjectKeep coroutines in Kotlin wrappers, not core API

Other Kotlin Caveats for Low-Level Code

This wasn’t an isolated issue. Kotlin differs from Java in other ways that make it risky for core interop code:

AreaJavaKotlin limitation
JNI declarationsstatic native boolean render(int, int)Needs @JvmStatic in a companion object; generates synthetic names
JNI header generationjavac -h works directlyNo header generation for Kotlin sources
Checked exceptionsEnforced at compile-timeKotlin ignores them (all unchecked)
Raw typesAllowed (List)Always requires generics (List<*>)
Wildcards? super? extends supportedOnly in / out; cannot express everything
Default paramsNot supported (overloads instead)Compiles to synthetic $default methods
Static membersstatic keywordRequires @JvmStatic in object/companion
Suspend functionsN/ACompiled to Continuation-based state machines, awkward for Java callers

Why This Matters for Library Code

A low-level library often deals with:

  • JNI ↔ JVM bridges
  • OpenGL or native rendering loops
  • Performance-critical calls that must inline
  • Reflection and MethodHandles

All of these require predictable bytecode and signatures. Kotlin often inserts synthetic classes ($Companion$DefaultImpls$WhenMappings) or adapts signatures in ways Java clients (and JNI) do not expect.


Why Keeping the Library Core in Java Makes Sense

BenefitWhy It Matters
One language to maintainSingle codebase, easier contributor onboarding, faster builds
Interop for everyoneJava APIs work in all JVM languages; Kotlin clients lose nothing; Java clients stay safe from Kotlin-only features
JNI friendlinessDirect mapping of Java types to JNI (int → jintboolean → jboolean); javac -h header generation works; avoids $Companion/$DefaultImpls surprises
Bytecode predictabilityNo synthetic baggage ($Companion$default$WhenMappings); avoids mismatched signatures; JIT optimizes exactly as written

Strategy: Java Core + Optional Kotlin API

The pattern I adopted (and which many frameworks use):

  • Core in Java
    • Predictable bytecode
    • JNI header generation
    • Works with MethodHandleVarHandleUnsafe
    • Safe for both Java and Kotlin clients
  • Optional Kotlin extensions (-ktx)
    • Extension functions for ergonomics
    • Coroutines (suspend wrappers)
    • Null-safety
    • DSLs for configuration

This is the same model Android Jetpack follows:
androidx.core in Java, androidx.core-ktx in Kotlin.


Takeaways

PointWhy
MethodHandle supportJava compiler emits exact signatures ((int,int)boolean), Kotlin falls back to (Object[])Object, causing runtime issues
Bytecode predictabilityJava produces direct, predictable bytecode; Kotlin adds synthetic constructs and indirections
JNI compatibilityJava maps directly to JNI types and header generation; Kotlin introduces complications
Best practiceKeep the core in Java for stability and performance; add Kotlin wrappers for ergonomics (DSLs, coroutines, null-safety)

interesting link: https://www.okoone.com/spark/technology-innovation/why-kotlin-swift-and-ruby-are-dropping-off-the-radar/

References

  1. Java SE Docs — MethodHandle and signature-polymorphic methods
    https://docs.oracle.com/javase/8/docs/api/java/lang/invoke/MethodHandle.html
  2. OpenJDK Wiki — Deconstructing MethodHandles
    https://wiki.openjdk.org/display/HotSpot/Deconstructing%2BMethodHandles
  3. Kotlin Docs — Functions and default arguments
    https://kotlinlang.org/docs/functions.html
  4. Medium — Kotlin Function Parameters and Default Values: Behind the Scenes
    https://medium.com/@AlexanderObregon/kotlin-function-parameters-and-default-values-behind-the-scenes-6551fa515fa1
  5. Kotlin Forum — Kotlin bytecode on default parameters
    https://discuss.kotlinlang.org/t/kotlin-bytecode-on-default-parameters/6159
  6. Kotlin Docs — Visibility modifiers (internal, etc.)
    https://www.digitalocean.com/community/tutorials/kotlin-visibility-modifiers-public-protected-internal-private
  7. YouTrack — KT-14416: Support of @PolymorphicSignature in Kotlin compiler
    https://youtrack.jetbrains.com/issue/KT-14416
  8. Baeldung — The @JvmStatic Annotation in Kotlin
    https://www.baeldung.com/kotlin/jvmstatic-annotation
  9. StackOverflow — How to call a static JNI function from Kotlin?
    https://stackoverflow.com/questions/57117201/how-to-call-a-static-jni-function-from-kotlin
  10. The golden age of Kotlin and its uncertain future https://shiftmag.dev/kotlin-vs-java-2392/

Rozhodnutí

Po skoro 30 letech od ‘obyčejné’ klavírní verze je tu verze orchestrální. Překvapivě bohatá a rozšiřující původní námět. Zvláště střední a závěrečná, epicky znějící část, se mi velmi líbí. Orchestraci z původní skladby vytvořil a vhodně rozšířil Maxmilián Šumbera.

Noční běžec

Night runner, my favourite one released ! I love the uncommon accents forming a distinct rhythm, interleaving with a faster pulse — like a heartbeat echoing the rhythm of feet hitting the ground in that first minute.

Olympus Pen-D

This is another nice half-frame camera — the Olympus PEN-D. It has an uncoupled meter and a smart way of setting aperture and shutter speed together. Works great and produces nice photos. Compared to the Canon Demi EE28 , it’s a bit bulkier, mostly due to the faster Zuiko 1.9 lens.

It features a Copal leaf shutter, fully mechanical, so no batteries are needed. Focusing is manual via a distance scale. Zone focusing works well once you get a feel for it.

Shutter speeds range from 8s to 1/500s.

GIS Visions 2045

I gave a presentation where GIS might evolve in 20 years from now as part of the GIS Ostrava 2025 conference on 5.3. 2025. it was great to see again colleagues ! get eye-contact with audience and not just virtual applause. Also nobody was showing physically thumbs-up or red heart (in that case I would call emergency), rather real spoken (I mean real sound wave based ) comments, real talk and smiles. That was the main topic of the talk – Spatial Interactive – with people, tech, discoveries. Step out of the ‘glass-illusion’ trap.

Spatial Interactive

Stanislav Sumbera, GIS Vision 2024, 5.3. 2025,GIS Ostrava 2025

  • What happens here is more important than what happens now.
  • Space is naturally interactive, enabling collaboration and sharing.
  • The computer is not behind a 2D glass screen but understands 3D space and interactions within it.
  • People learn through observation, collaboration, and play.
  • Community Computer
  • Projective Augmented Reality (Projective AR)
  • Bret Victor – Dynamicland

image sources:https://gislab.utk.edu/tag/ar-sandbox/ , Dyamicland.org, Lightform

  • HMD / Head-Mounted Displays – Apple Vision Pro
  • Spatial Computing
  • Control through advanced gestures
  • Super persistence” of objects – digital objects remain anchored as if truly part of the physical world
  • Pseudo-haptic feedback – realism in rendering creates the illusion of tactile response
  • Currently at the UNIX Workstation” stage of the 1980s – showcasing possibilities that will later become accessible to everyone.
  • Also bloged here

2. Web, Open Source, and Technology Accessibility

  • From Google Maps → OpenLayers → Leaflet → MapBoxGL → MapLibreGL → ?
  • Each step represents greater availability, democratization, and accessibility of mapping technology, pushing development forward.
  • How difficult was it to render an image in 1993? How difficult was it to share that image with others? And today?
  • What is difficult, expensive, yet possible today that will become commonplace in 20+ years?

3. Lifespan of Data vs. Lifespan of Technology

  • WMS – Simple for visualization
  • Vector tiles – More complex to render (OGC API Tiles, MapBox Tiles, MapLibre Tiles – MLT)
  • 3D tiles – OGC 3D Tiles, evolving standards for spatial data
  • More aesthetics, smoothness, and artistic expression in maps
  • Real-time rendering techniques, such as Gaussian Splat, for next-generation visualization

from Book: Eneterpise SOA by Krafzig, Banke, Slama

4. Scanning Spaces and Objects

  • 3D scanning is accessible to everyone
  • Spatial Video, Spatial Photo
  • 3D scanning is as simple as taking a photo
  • Photorealistic scanning

5.Precise Geolocation ~2-10 cm

  • VPS (Visual Positioning System) – accuracy < 10 cm
  • 5G geolocation
  • Affordable high-precision GNSS + RTK/PPP (< 10 cm)
  • Accessible VPS from panoramic images, Mapy.cz?

6. AI – Welcome to the Jungle

  • NPCs have become “thinking machines” (are we, on other side, turning into NPCs ourselves? aka Jumanji 2 )

Image from Jumanji 2,driver – Mason Pike ?

  • The Chinese Room paradox – an English speaker perfectly assembles answers in Chinese following instructions without understanding the Chinese language and symbols meaning.
  • AI cannot create true originality but excels at combining and compiling existing inputs – a “super plagiarist” or “super puzzle resolver” ?
  • Might replace a significant amount of human (intellectual + routine) labor – in GIS (georeferencing, recognition/classification), programming/syntax, and more
  • “Hard work for machines, thinking for people” (Tomáš Baťa) is evolving into “(Pre)thinking* for machines, creativity/ideas for people” (in Czech Language : pre-mýšlení)
  • AI model marketplace – grow (cultivate) your unique “thought twin” that integrates into an open AI network.
  • Developer Twin: Blog post

Wining is singularity, whereas losing conforms to a pattern.

from page 16 of the great book uncommon sense, common nonsense. by Jules Goddard and Tony Eccles.

and p. 39: It is better to be first than it is to be better

2 quotes  form czech book on Bata  system :

Taylor, Fayol, Ford, and Baťa put an end to the old type of entrepreneur for good. They argued that profit does not depend on the numerically lowest wages, but on the highest and most efficient work performance, during which the worker works as if he were working for himself.

“Baťa’s factories produced and supplied most of the construction materials themselves. They had their own brickyards, carpentry, joinery, and locksmith workshops, which supplied standardized interior fittings to all homes, produced neon tubes, flooring, in short, almost everything they needed. And if there was something not included in their production program, they purchased it directly from manufacturers (excluding intermediaries).”

iKatastr novinky

Novinky

24.7.’25 Podívejte se na zajimavé srovnání reality na fotce (kinofilm) s virtuálním pohledem do stejného místa v iKatastr 3d.

Držková

20.6.’25: Nová 3D verze, obsahuje reliéf terénu, výškové obrysy budov a využívá akceleraci grafické karty. Vyzkoušejte v testovacím provozu https://ikatastr.cz/3d

Beskydy

23.2.’25: zlepšeno rozlišení základních map pro ‘retina’ obrazovky. Oprava drobných chyb.

17.2.’25 aktualizována mapová komponenta Leaflet na poslední verzi 1.9.4.

27.1.’25: Přidána vrstva označující nemovitosti, které obsahují cenový údaj v katastru nemovitostí. Vyzkoušejte např zde. Ovšem sdělení konkrétní ceny je pouze na vyžádání na katastru. Viz ceník zde, položka 4021 a 4022.

13.1.’25: Export 1000 parcel do CSV souboru (test rychlosti procházení záznamy a exportu): https://www.youtube.com/watch?v=frBXLgSkHgU

2.1.’25 : Přidána  možnost exportu parcel do csv souboru.

Screenshot

18.12. Přidány vrstvy zasíťování (voda, elektřina, plyn, kanalizace, apod). vyzkoušejte zde.

A také vrstvy leteckých snímků z minulých let, které můžete jednoduše procházet –video zde.

Nová videa pro náročné:  iKatastr.cz na Apple Vision Pro a  Test 3D prototypu  na Apple Vision Pro

Apple Vision Pro: Enabling Spatial Interaction

We have various terms for AR – like Mixed Reality, Metaverse, Spatial-ware, XR. Among these, Apple’s term “Spatial Computing” stands out for its emphasis on integrating physical space and digital interactivity. This resonates with me, as the concept of “Spatial” reflects how we model and interact with space in meaningful ways. Years ago, I made up a new term “SpatialIn”—an open-ended label where “In” simply means Spatial is “in.” Later, with advancements like ARKit, I extended this idea into “Spatial Interactive,” emphasizing the interactive potential of space around us behaving like a dynamic canvas. Vision Pro aligns perfectly with this vision. After testing Vision Pro , here are my key observations:

  1. Hands-Free Interaction

Vision Pro’s hands-free interaction feels intuitive. Manipulating virtual objects with gestures or gaze eliminates barriers and enhances usability. Fluent hand movements remind me of my Tai-Chi classes from years ago.

  1. From VR to True Mixed Reality Immersion

Unlike VR, Vision Pro allows safer navigation in real spaces while engaging with virtual elements. It maintains spatial awareness and visual contact with reality, making it both practical and immersive.

  1. Unmatched Persistence

Vision Pro’s capability to retain virtual object placement across sessions is impressive. This feature is critical for practical applications such as architectural design, where models need to stay precisely where placed for accurate spatial referencing, or in education, where persistent virtual setups can create consistent and engaging learning environments. I found a model I placed earlier in the day still standing on the lower floor of the building—exactly where I left it. This happens without explicit relocalization notification for the user, as the virtual model sticks to the physical space even across different floors. A must for advanced spatial computing design as virtual space must keep integrity similar to physical one.

  1. Feeling Rendering on My Hands – sort of

The wide field of view and detailed lighting ensure a natural integration of digital and physical environments. Soft shadows and consistency make virtual elements feel tangible. Fidelity is so high that it creates the illusion of tactile sensation when interacting with virtual models. While purely subjective, this visual illusion convincingly engages my sense of touch, making the experience feel remarkably real to me. This visual-feel integration adds a layer of immersion that goes beyond sight and sound, engaging the sense of presence in a way that feels almost instinctive.

Here is a little example – while using only flat browser with WebGL powered MapLibreGL there: Update 07/2025 -live version here, e.g. : https://ikatastr.cz/3d/#kde=50.741216,15.001038,15.4,50,75&mapa=letecka&vrstvy=budovy3d,peaks,zsj,ku,obce,parcelybudovy&info=50.732718,14.984554

As there is no 3D map from Apple to test on the device by default, I had to convert a gltf to USDZ and send it to device for QuickLook to get experience of how 3D city would look like there.Here it goes: