title: In Java / Android, why am I able to get an integer file descriptor from ParcelFileDescriptor?
body: <p>I have solved a problem I had while coding on the NDK, but I'm not sure the solution is canonical, or if there is a canonical way to do this. First a description of what I did:</p>
  
  <p>It appears that I cannot access an integer file descriptor value using Java's File or FileDescriptor objects:
  <a href="http://developer.android.com/reference/java/io/File.html" rel="nofollow">http://developer.android.com/reference/java/io/File.html</a>
  <a href="http://developer.android.com/reference/java/io/FileDescriptor.html" rel="nofollow">http://developer.android.com/reference/java/io/FileDescriptor.html</a></p>
  
  <p>But I can using Android's ParcelFileDescriptor object:
  <a href="http://developer.android.com/reference/android/os/ParcelFileDescriptor.html" rel="nofollow">http://developer.android.com/reference/android/os/ParcelFileDescriptor.html</a></p>
  
  <p>So I can get the integer fd to my native code in this way:</p>
  
  <pre><code>pfd = ParcelFileDescriptor.open(new File("blah"), MODE_WRITE_ONLY);
  myNativeFunction(pfd.getFd());
  </code></pre>
  
  <p>Why does this work? Wouldn't the file descriptor integer field be private in the File object, since I can't access it even when I own the object? So how does the ParcelFileDescriptor get to access this presumably private field just by being passed the object in one of its public methods? Do I even want to know?</p>