简体   繁体   中英

How to hook into an auto-generated Java method?

Edit: What started as a low-priority question to make my work easier has become a really interesting exercise in Java witchcraft. Thanks for your input, everyone!

I'm working with auto-generated Java code (specifically, code generated by AnyLogic) that produces a method called onChange() . I'd like to call my own method when onChange() is called. Is there any way to "hook into" onChange() via reflection or other standard Java mechanism?

One solution that I could suggest is using Proxy objects. Here is a tutorial that might be of some help to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM