java - When extending class with static methods that I don't actually use, will those methods be compiled? -


i'm extending class, has lot of static methods. client code extending class typically use 1 or 2 of methods. there way methods not used not compiled?

no, compiler not exclude unused code snippet making way final compilation. compiler can't infer sort of information until runtime anyway; doesn't know if particular method used in 1 way or another.

however, developer can prevent scenario happening.

there tools out there, such pmd, findbugs, , sonarqube can run static analysis on code determine if there's unused methods in code. if have unit test suite, tools can show uncovered/unhit code branches (such if statement). modern ide intellij idea can same while 1 developing.

for general situation though, there unnecessary inheritance going on; if realistically need use 3 methods, elect import them in static imports instead of relying on inheritance job done. way, code uses parts needs , doesn't have of excess baggage of doesn't need.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -