简体   繁体   中英

Override public final method in Java (reflection?!)

I'm getting into a problem, when I was trying to create a custom LayoutAnimationController for an Android project. It has the method

public final Animation getAnimationForView(View v)

For my custom LayoutAnimationController, I need to override this method, because each view should get a "unique" animation. Is it possible to override public final methods by using reflection or similar techniques, or do you have an alternative idea?

I know that something similar had been discuses in override java final methods via reflection or other means? but the "solution" which came up there, was pretty specific to the problems of the user and did not completely answer the question of overriding final methods.

It looks like LayoutAnimationController is not intended to be used like this.

If you would be able to override getAnimationForView(View v) with the functionality you want most methods/constructors of LayoutAnimationController would make no sense since this class is created for using a single animation (with different delays) on multiple views.

Maybe it is better to look into the source and create you own animation controller based on this information.

An old question, but I still feel I should answer as there doesn't seem to be a possible solution using LayoutAnimationController .

I ended up overriding AnimationSet and just moved the LayoutAnimationController functionality to that class. Of course, together with my custom code.

Finally, I just have to rant about this: this is hardly the first time I ran into some sort of private / final / access denied in your preferred way code in Google's framework. They seem to find it hilarious if they give us programmers a hard time. I understand that Transformation only Animation s are there for performance, but sometimes we just need something different and disabling us through such childish ways is beyond ridiculous. /rant

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