{"action":"closed","issue":{"url":"https://api.github.com/repos/swig/swig/issues/530","labels_url":"https://api.github.com/repos/swig/swig/issues/530/labels{/name}","comments_url":"https://api.github.com/repos/swig/swig/issues/530/comments","events_url":"https://api.github.com/repos/swig/swig/issues/530/events","html_url":"https://github.com/swig/swig/issues/530","id":108148586,"number":530,"title":"[Java] error: getCPtr(CLASS_NAME) has protected access in CLASS_NAME","user":{"login":"SergeySeroshtan","id":2228157,"avatar_url":"https://avatars.githubusercontent.com/u/2228157?v=3","gravatar_id":"","url":"https://api.github.com/users/SergeySeroshtan","html_url":"https://github.com/SergeySeroshtan","followers_url":"https://api.github.com/users/SergeySeroshtan/followers","following_url":"https://api.github.com/users/SergeySeroshtan/following{/other_user}","gists_url":"https://api.github.com/users/SergeySeroshtan/gists{/gist_id}","starred_url":"https://api.github.com/users/SergeySeroshtan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SergeySeroshtan/subscriptions","organizations_url":"https://api.github.com/users/SergeySeroshtan/orgs","repos_url":"https://api.github.com/users/SergeySeroshtan/repos","events_url":"https://api.github.com/users/SergeySeroshtan/events{/privacy}","received_events_url":"https://api.github.com/users/SergeySeroshtan/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-24T14:59:09Z","updated_at":"2015-09-28T14:13:54Z","closed_at":"2015-09-28T14:13:54Z","body":"## Preconditions:\r\n\r\n1. Use C++ namespaces.\r\n2. Define %nspace for classes in the SWIG interface classes.\r\n3. Use constructor in some class which accepts as parameter class from different namespace.\r\n\r\n## Example:\r\n\r\n### example.h\r\n\r\n```.cpp\r\nnamespace details {\r\n  class Wheel {\r\n  public:\r\n    explicit Wheel(double radius) : radius_(radius) {}\r\n    double radius() const { return radius_; }\r\n  private:\r\n    double radius_;\r\n  };\r\n}\r\n\r\nnamespace factory {\r\n  class Car {\r\n  public:\r\n    explicit Car(const details::Wheel& wheel) : wheel_(wheel) {}\r\n    details::Wheel wheel() const { return wheel_; }\r\n  private:\r\n    details::Wheel wheel_;\r\n  };\r\n}\r\n```\r\n\r\n### example.cxx\r\n\r\n```cpp\r\n/* File : example.cxx */\r\n\r\n#include \"example.h\"\r\n```\r\n\r\n### example.i\r\n\r\n```cpp\r\n/* File : example.i */\r\n%module example\r\n\r\n%{\r\n#include \"example.h\"\r\n%}\r\n\r\n%pragma(java) jniclasspackage= %{com.bug%}\r\n\r\n%nspace details::Wheel;\r\n%nspace factory::Car;\r\n\r\n/* Let's just grab the original header file here */\r\n%include \"example.h\"\r\n```\r\n\r\n### runme.java\r\n\r\n```java\r\n// This example illustrates how C++ classes can be used from Java using SWIG.\r\n// The Java class gets mapped onto the C++ class and behaves as if it is a Java class.\r\n\r\nimport details.Wheel;\r\nimport factory.Car;\r\n\r\npublic class runme {\r\n  static {\r\n    try {\r\n        System.loadLibrary(\"example\");\r\n    } catch (UnsatisfiedLinkError e) {\r\n      System.err.println(\"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\\n\" + e);\r\n      System.exit(1);\r\n    }\r\n  }\r\n\r\n  public static void main(String argv[])\r\n  {\r\n    System.out.println( \"Create car\" );\r\n    Car car = new Car(new Wheel(20));\r\n    System.out.println( \"Car's wheel radius: \" + car.wheel().radius());\r\n    car.delete();\r\n    System.out.println( \"Goodbye\" );\r\n  }\r\n}\r\n```"}}