快速编辑私有变量

时间:2018-08-20 06:28:57

标签: java reflection

在我的项目中,我想快速阅读并修改私有变量。我最初打算进行反思,但我的想法是效率太低。

//Reference for what I need to get data from.
public class SomeControllerInALibraryThatICantEdit {

    //I can easily get an instance of the controller
    public static final SomeControllerInLargeLibrary instance;

    //I need to read from and make changes to the data object quickly.
    //It is final, so I don't need to worry about this object changing or being reset.
    private final Subclass dataClass = new Subclass();

    private class Subclass {

        //I can get a pointer to this once then treat it like any other array.
        public float[] arr;


        //This is the problematic part. I need to be able to quickly check changes and 
        //set this every update. Keeping in mind there are multiple dataPoints.
        public short dataPoint;

    }

}

获取和设置 dataPoint 的快速有效的方法是什么?我可以使用反射,但是我希望有一种更好的方法来解决此问题。我可以通过某种方式制作代表子类的Pojo并将其指针链接在一起吗?

如果我只是分叉库并使其与我正在做的事情更好地工作,那将违反我项目的目的。

0 个答案:

没有答案