title: reinterpret_cast vs. c-style cast JNI
body: <p>I'm experiencing some extremely weird behaviour using JNI when using <code>reinterpret_cast</code> vs. <code>C-style casting</code>..</p>
  
  <p>If I call my function from Java using:</p>
  
  <pre><code>ArrayList&lt;String&gt; list = instance.tokenize("Я Я", "[\\w+0-9-_]+", 0x01);
  
  for (String str : list) {
      System.out.println(str);
  }
  </code></pre>
  
  <p>It prints <code>Я \n Я</code> which is fine using C-Style casting as shown below <code>(casting jchar* to wchar_t*)</code>:</p>
  
  <pre><code>extern "C" JNIEXPORT jobject Java_Native_tokenize(JNIEnv* env, jobject obj, jstring jquestion, jstring jregex, jint mode)
  {
      const wchar_t* utf16question = (const wchar_t*)env-&gt;GetStringChars(jquestion, false);
      const wchar_t* utf16regex = (const wchar_t*)env-&gt;GetStringChars(jregex, false);
  
      std::wregex pattern(utf16regex, static_cast&lt;std::regex::flag_type&gt;(mode));
      auto itr_beg = std::regex_iterator&lt;const wchar_t*&gt;(utf16question, utf16question + env-&gt;GetStringUTFLength(jquestion), pattern);
      auto itr_end = std::regex_iterator&lt;const wchar_t*&gt;();
  
      jclass array_list_class = env-&gt;FindClass("Ljava/util/ArrayList;");
      jmethodID add_method = env-&gt;GetMethodID(array_list_class, "add", "(Ljava/lang/Object;)Z");
      jobject array_list = env-&gt;NewObject(array_list_class, env-&gt;GetMethodID(array_list_class, "&lt;init&gt;", "()V"));
  
      while (itr_beg != itr_end)
      {
          std::wstring wstr = itr_beg++-&gt;str();
          jstring str = env-&gt;NewString((jchar*)wstr.c_str(), wstr.size());
          env-&gt;CallVoidMethod(array_list, add_method, str);
      }
  
      env-&gt;ReleaseStringChars(jregex, (jchar*)utf16regex);
      env-&gt;ReleaseStringChars(jquestion, (jchar*)utf16question);
      return array_list;
  }
  </code></pre>
  
  <p>That is the exact output I needed..</p>
  
  <p>However, being the strictly C++ code in C++ guy that I am, I decided to replace my C-Style casts (specifically the first two casts) with a <code>reinterpret_cast</code>.</p>
  
  <p>Behold the bug that is annoying me.. It prints <code>Я \n Я \n 寵</code>.</p>
  
  <p>Where in the world did that Asian character come from?! All because I changed the first two C-Style casts to <code>reinterpret_cast</code>.</p>
  
  <p>Any reasons why this might happen? I tried <code>static_cast</code>, it won't work obviously.</p>