Is it OK to have so many deprecated methods in backward-compatible code?

后端 未结 1 424
情歌与酒
情歌与酒 2020-12-31 19:54

I\'m writing an Android application which is targeted to API level 15 but I also want to keep backward-compatibilty with older API levels (min-sdk 7).

I\'m going to

相关标签:
1条回答
  • 2020-12-31 20:46

    You have to ask yourself a few questions:

    • Was it deprecated for the API levels that will be executing this code?
    • If so, is an alternative suggested or available?

    In your case, getWidth() is deprecated in favor of using getSize(Point), which requires API level 13. So prior to API level 13, all you have is getWidth(), which at the time was not deprecated. The reason these deprecated methods are kept around is largely with backwards compatibility in mind (along with avoiding breaking everyone's apps which depend on it).

    So to answer your questions, yes, this is fine in this case, and yes, it's a good use of @SuppressWarning("deprecation").

    0 讨论(0)
提交回复
热议问题