Hooking an existing method in Java

前端 未结 5 1385
清歌不尽
清歌不尽 2021-02-19 14:08

I want to hook the method System.out.print in Java and have the ability to read/change the variables used in the method before the part of the method is called that actually add

5条回答
  •  无人及你
    2021-02-19 14:40

    You can reassign System.out (and System.err) to another object which does what you want to do with it. Said object usually gets the old System.out value so that output can be made in the end.

    This is usually done in main() and influences the whole JVM.

    We use this to have automatic wrapping at 130 columns in a very peculiar setting where longer lines are truncated.

提交回复
热议问题