override java final methods via reflection or other means?

前端 未结 6 1653
醉梦人生
醉梦人生 2020-12-15 09:28

This question arise while trying to write test cases. Foo is a class within the framework library which I dont have source access to.

public class Foo{
  pub         


        
6条回答
  •  再見小時候
    2020-12-15 09:50

    If the variable returned by getX() is not final you can use the technique explained in What’s the best way of unit testing private methods? for changing the value of the private variable through Reflection.

提交回复
热议问题