diff --git a/java-panama/src/main/java/com/baeldung/java/panama/core/Greetings.java b/java-panama/src/main/java/com/baeldung/java/panama/core/Greetings.java index 7c210f1216..e6d596dbf0 100644 --- a/java-panama/src/main/java/com/baeldung/java/panama/core/Greetings.java +++ b/java-panama/src/main/java/com/baeldung/java/panama/core/Greetings.java @@ -5,7 +5,6 @@ import java.lang.invoke.MethodHandle; import static java.lang.foreign.ValueLayout.*; - public class Greetings { public static void main(String[] args) throws Throwable { @@ -20,14 +19,14 @@ public class Greetings { FunctionDescriptor descriptor = FunctionDescriptor.of(JAVA_INT, ADDRESS); MethodHandle methodHandle = loaderLookup.lookup(symbolName) - .or(() -> stdlibLookup.lookup(symbolName)) - .map(symbolSegment -> nativeLinker.downcallHandle(symbolSegment, descriptor)) - .orElse(null); + .or(() -> stdlibLookup.lookup(symbolName)) + .map(symbolSegment -> nativeLinker.downcallHandle(symbolSegment, descriptor)) + .orElse(null); - - if(methodHandle == null){ + if (methodHandle == null) { throw new NoSuchMethodError("Method Handle was not found"); - }; + } + ; try (MemorySession memorySession = MemorySession.openConfined()) { MemorySegment greetingSegment = memorySession.allocateUtf8String(greeting); diff --git a/java-panama/src/main/java/com/baeldung/java/panama/core/MemoryAllocation.java b/java-panama/src/main/java/com/baeldung/java/panama/core/MemoryAllocation.java index 710f1a1e87..557a0695cc 100644 --- a/java-panama/src/main/java/com/baeldung/java/panama/core/MemoryAllocation.java +++ b/java-panama/src/main/java/com/baeldung/java/panama/core/MemoryAllocation.java @@ -5,15 +5,12 @@ import java.lang.foreign.MemorySession; import java.lang.foreign.ValueLayout; import java.lang.foreign.SegmentAllocator; - - public class MemoryAllocation { public static void main(String[] args) throws Throwable { - try (MemorySession session = MemorySession.openConfined()) { - String[] greetingStrings = {"hello", "world", "panama", "baeldung"}; + String[] greetingStrings = { "hello", "world", "panama", "baeldung" }; SegmentAllocator allocator = SegmentAllocator.implicitAllocator(); MemorySegment offHeapSegment = allocator.allocateArray(ValueLayout.ADDRESS, greetingStrings.length); for (int i = 0; i < greetingStrings.length; i++) { diff --git a/java-panama/src/main/java/com/baeldung/java/panama/core/MemoryLayout.java b/java-panama/src/main/java/com/baeldung/java/panama/core/MemoryLayout.java index 620577f887..647247b54b 100644 --- a/java-panama/src/main/java/com/baeldung/java/panama/core/MemoryLayout.java +++ b/java-panama/src/main/java/com/baeldung/java/panama/core/MemoryLayout.java @@ -10,18 +10,13 @@ import static java.lang.foreign.MemoryLayout.sequenceLayout; import static java.lang.foreign.MemoryLayout.structLayout; import static java.lang.foreign.ValueLayout.*; - public class MemoryLayout { public static void main(String[] args) { - GroupLayout pointLayout = structLayout( - JAVA_DOUBLE.withName("x"), - JAVA_DOUBLE.withName("y") - ); + GroupLayout pointLayout = structLayout(JAVA_DOUBLE.withName("x"), JAVA_DOUBLE.withName("y")); - SequenceLayout ptsLayout = sequenceLayout(10, - pointLayout); + SequenceLayout ptsLayout = sequenceLayout(10, pointLayout); VarHandle xvarHandle = pointLayout.varHandle(PathElement.groupElement("x")); VarHandle yvarHandle = pointLayout.varHandle(PathElement.groupElement("y")); diff --git a/java-panama/src/main/java/com/baeldung/java/panama/jextract/Greetings.java b/java-panama/src/main/java/com/baeldung/java/panama/jextract/Greetings.java index 90d8e8f253..43b575d52a 100644 --- a/java-panama/src/main/java/com/baeldung/java/panama/jextract/Greetings.java +++ b/java-panama/src/main/java/com/baeldung/java/panama/jextract/Greetings.java @@ -2,7 +2,7 @@ package com.baeldung.java.panama.jextract; import java.lang.foreign.MemorySegment; import java.lang.foreign.MemorySession; -// Generate JExtract bingings before uncommenting +// Generate JExtract bindings before uncommenting // import static foreign.c.stdio_h.printf; public class Greetings { @@ -12,8 +12,8 @@ public class Greetings { try (MemorySession memorySession = MemorySession.openConfined()) { MemorySegment greetingSegment = memorySession.allocateUtf8String(greeting); - // Generate JExtract bingings before uncommenting - // printf(greetingSegment); + // Generate JExtract bingings before uncommenting + // printf(greetingSegment); } } }