<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          JavaCPPJava 訪問(wèn) C++ 方法

          聯(lián)合創(chuàng)作 · 2023-09-28 14:08

          JavaCPP提供了在Java中高效訪問(wèn)本地C++的方法。采用JNI技術(shù)實(shí)現(xiàn),支持所有Java實(shí)現(xiàn)包括Android系統(tǒng),AvianRoboVM

          JavaCPP提供了一系列的Annotation將Java代碼映射到C++代碼,并使用一個(gè)可執(zhí)行的jar包將C++代碼轉(zhuǎn)化為可以從JVM內(nèi)調(diào)用的動(dòng)態(tài)鏈接庫(kù)文件。

          Maven:

          <dependency>
              <groupId>org.bytedeco</groupId>
              <artifactId>javacpp</artifactId>
              <version>0.11</version>
          </dependency>

          使用方法:

          C++:

          #include <string>
          
          namespace LegacyLibrary {
              class LegacyClass {
                  public:
                      const std::string& get_property() { return property; }
                      void set_property(const std::string& property) { this->property = property; }
                      std::string property;
              };
          }

          Java:

          import org.bytedeco.javacpp.*;
          import org.bytedeco.javacpp.annotation.*;
          
          @Platform(include="LegacyLibrary.h")
          @Namespace("LegacyLibrary")
          public class LegacyLibrary {
              public static class LegacyClass extends Pointer {
                  static { Loader.load(); }
                  public LegacyClass() { allocate(); }
                  private native void allocate();
          
                  // to call the getter and setter functions 
                  public native @StdString String get_property(); public native void set_property(String property);
          
                  // to access the member variable directly
                  public native @StdString String property();     public native void property(String property);
              }
          
              public static void main(String[] args) {
                  // Pointer objects allocated in Java get deallocated once they become unreachable,
                  // but C++ destructors can still be called in a timely fashion with Pointer.deallocate()
                  LegacyClass l = new LegacyClass();
                  l.set_property("Hello World!");
                  System.out.println(l.property());
              }
          }
          瀏覽 17
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  精品国产黄色电影 | 在线免费视频a | 日韩无码AV电影 | a人妻免费视频 | 爽 好紧 别夹 喷水欧美 |