自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Java 訪問 C++ 方法 JavaCPP

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

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

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

[[139194]]

Maven:

  1. <dependency> 
  2.     <groupId>org.bytedeco</groupId> 
  3.     <artifactId>javacpp</artifactId> 
  4.     <version>0.11</version> 
  5. </dependency> 

使用方法:

C++:

  1. #include <string> 
  2.   
  3. namespace LegacyLibrary { 
  4.     class LegacyClass { 
  5.         public
  6.             const std::string& get_property() { return property; } 
  7.             void set_property(const std::string& property) { this->property = property; } 
  8.             std::string property; 
  9.     }; 

Java:

  1. import org.bytedeco.javacpp.*; 
  2. import org.bytedeco.javacpp.annotation.*; 
  3.   
  4. @Platform(include="LegacyLibrary.h"
  5. @Namespace("LegacyLibrary"
  6. public class LegacyLibrary { 
  7.     public static class LegacyClass extends Pointer { 
  8.         static { Loader.load(); } 
  9.         public LegacyClass() { allocate(); } 
  10.         private native void allocate(); 
  11.   
  12.         // to call the getter and setter functions  
  13.         public native @StdString String get_property(); public native void set_property(String property); 
  14.   
  15.         // to access the member variable directly 
  16.         public native @StdString String property();     public native void property(String property); 
  17.     } 
  18.   
  19.     public static void main(String[] args) { 
  20.         // Pointer objects allocated in Java get deallocated once they become unreachable, 
  21.         // but C++ destructors can still be called in a timely fashion with Pointer.deallocate() 
  22.         LegacyClass l = new LegacyClass(); 
  23.         l.set_property("Hello World!"); 
  24.         System.out.println(l.property()); 
  25.     } 

 

責(zé)任編輯:王雪燕 來源: 開源中國社區(qū)
相關(guān)推薦

2010-01-18 10:01:48

C++中訪問控制

2010-01-19 10:04:30

C++類

2010-02-03 16:35:45

C++回文

2010-02-03 10:50:33

C++多態(tài)

2010-02-02 14:36:08

C++ Cstring

2010-02-02 14:55:35

C++訪問控制符

2010-01-11 14:05:01

C++學(xué)習(xí)方法

2010-01-26 09:50:30

C++接口

2010-01-25 13:19:44

C++詞法分析

2010-01-18 14:41:52

Visual C++開

2010-01-26 17:35:09

C++棧

2010-01-27 15:54:49

C++實(shí)現(xiàn)程序

2010-02-05 11:23:01

C++聲明語法

2010-02-06 10:50:10

C++統(tǒng)計(jì)對象個數(shù)

2010-02-02 09:32:32

C++ typedef

2010-01-14 14:27:46

Visual C++訪

2011-07-13 11:34:58

CC++時間函數(shù)

2011-04-08 09:52:44

C++C#DLL

2009-09-09 13:47:38

C++訪問SqlCe

2010-02-05 17:09:19

C++創(chuàng)建Web服務(wù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號