hello. i have an (external) library class that crashes in some rare circumstances. so i want to override one method and yolo suppress the exception. the method is not public though. it seems that i can override it if i make a new file with the package of that class (
package library.package
). is there a reason i shouldn't do this?
c
crummy
06/17/2021, 10:51 PM
perhaps this is a use case for reflection?
l
louiscad
06/17/2021, 11:07 PM
If you have a way to inject the instance where the override is missing (including with reflection), yes, you can have a wrapper using
Proxy
from Java reflection to handle the missing override and delegate for the other ones.
l
li'lfluf
06/17/2021, 11:24 PM
i don't quite see why would I want to use reflection instead of simply having a class in a “fake” library package?
l
louiscad
06/17/2021, 11:28 PM
If you don't need reflection, don't use it, for sure
although if you're on the desktop JVM and not Android, you could also perform the fixup in -javaagent (which is how I unit test my aforementioned transforms)