开发者

Override androids implementation of TimeUnit

As these 2 questions clearly show, the android implementation of the jdk do not include some of the java.util.concurrent.TimeUnit enum values, particularly DAYS.

Since I am extensively using a common library which references TimeUnit.DAYS I need the enum value to exist. I know开发者_如何学JAVA the functionality of TimeUnit.DAYS is the same as TimeUnit.HOURS * 24 however I can't change the implementation of the referenced library.

How would I go about overriding the android jdk implementation of this Enum so that I stop getting the NoSuchFieldError at runtime?

Thanks for the help!


You are not likely to find a solution. Even if you could override the built in TimeUnits class (I don't believe you can) you would have no way to feed the new one into your library and get it to work.

In normal java you could replace the classloader before loading the library but that would be a really bad (and difficult) solution anyway.

If your library is open-source or if you own it, I'd recommend fixing it and rebuilding--seems pretty straight-forward. If you submit a patch and tell them why then it should automatically be included in future versions.

If you don't own it, you have to get the person or group who does to rebuild it (This is the reason old-school programmers hate closed source, even if you are willing to do it yourself, you are often completely blocked).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜