Class NativeStringLength

java.lang.Object
net.jrodolfo.java_evolution.java22.foreign_function.NativeStringLength

public class NativeStringLength extends Object
Demonstrates a Java 22 foreign function call to the native strlen function.

The example copies a Java string into native memory, passes the memory address to C strlen, and receives the string length back as a Java long. This shows the foreign-function side of the Foreign Function and Memory API without requiring a custom native library.

The example uses JAVA_LONG for C size_t, which matches the 64-bit platforms targeted by this repository. The native linker provides canonical layouts for platform-dependent C types when code must support other data models.

  • Constructor Details

    • NativeStringLength

      public NativeStringLength()
  • Method Details

    • lengthOf

      public ForeignFunctionCallResult lengthOf(String text) throws Throwable
      Calls native strlen for the supplied text.
      Parameters:
      text - the Java text copied into native memory
      Returns:
      the native call result
      Throws:
      Throwable - if the native function cannot be linked or invoked