1 Reply Latest reply: Apr 7, 2013 4:57 PM by James_D RSS

    Any way to access "package private" data?

      So I was looking at TriangleMesh because I have a class that originally extended box, and then now I need 3D objects that use mesh's. Now I am changing it to MeshView and working that way, but I found something interesting in the API

      Methods in javafx.scene.shape that return TriangleMesh 
      Modifier and Type     Method and Description
      (package private) static TriangleMesh     Box.createMesh(float w, float h, float d) 
      Fields in javafx.scene.shape with type parameters of type TriangleMesh 
      Modifier and Type     Field and Description
      private java.util.HashMap<java.lang.Integer,TriangleMesh>     PredefinedMeshManager.boxCache 
      Now this is interesting to me, because I was just going to make a 3D box, and use it as a default, but if there is a "predefinedMeshManager" and there is a "predefined Mesh for Box" I would like to access it, and use it, if possible. When you goto these packages you cannot see the private classes.

      So is there a way to be able to grab that box mesh, and use it when needed? Or should I just import a 3d Box and use it as a mesh?


        • 1. Re: Any way to access "package private" data?
          Well, you could probably access these using reflection, assuming you have SecurityManager permissions to access declared members. However, you shouldn't. Firstly, private and package-private members are not part of the public API, so there is no guarantee that those methods and fields will still be there in a later release. Additionally, you have no guarantees that any class invariants are preserved when you access those members, so behavior of the objects is not properly defined.