9

I'm developing an Android library and I wanted to clean all warnings. Most of them is due to unused methods. I don't want to remove this methods from the class as it could be used by other developer.

Should I:

  • add @SuppressWarnings("unused") on methods or class?
  • remove the methods anyway?
  • use this methods in the project app that is using the library (for development purpose). This will remove the warning but will add some junk code to the app?
  • or?

If I annotate the class to suppress this warnings it will solve the issue but it will also prevent me for removing real unused methods.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Hugo Gresse
  • 17,195
  • 9
  • 77
  • 119

1 Answers1

0

Unused warning should only appear if a private method is never used. If a private method is never used, it is indeed dead code, since nobody could call it from outside. You should delete these methods. I hope you are using a version control system, so you can still find methods in the repository history.

WonderCsabo
  • 11,947
  • 13
  • 63
  • 105
  • 3
    Android Studio display unused for public methods too cf https://www.dropbox.com/s/7ap7k50jhcb366s/Capture%20d%27%C3%A9cran%202015-06-26%2010.51.39.png?dl=0 – Hugo Gresse Jun 26 '15 at 08:51
  • 5
    You should [disable](http://stackoverflow.com/a/26095746/747412) that inspection for public methods, it is incorrect in case of libraries. – WonderCsabo Jun 26 '15 at 09:28
  • Though not clear in the question, it seems more likely the issue has to do with `public` methods that may actually be used by a project that makes use of the library. In this case, it isn't safe to delete things that AS reports as unused; AS just doesn't know about the usages. – Myk Willis Mar 14 '17 at 20:10
  • I only spoke about deleting private methods, and actually said the inspection should be disabled for public ones. – WonderCsabo Mar 14 '17 at 22:36
  • Hmm, can't find the inspection for "method ... is never used" in Android Studio. Anyone? – SMBiggs Sep 14 '19 at 00:33