Consider a private method which is called from JNI and not used otherwise, generating a compiler warning about an unused method:
private void someMethodCalledOnlyFromJNI() { // WARNING: method is never used
// ....
}
This is some legacy code in Java 1.4 - so no dice on @SuppressWarnings
.
What hack would you use to suppress this compiler warning?
Edit: Obviously this is just a warning and it can easily be ignored. But, personally, I hate warnings in my code just as much as I don't want to see errors in it. AFAIC - my code should have 0 warnings, it might be an exaggeration, but I am very pedantic about this.
Just as an example, someone might see this function, not know it is used from JNI, and simply delete it.
protected
(and add a comment for the reason why) - bearable
Windows > Preferences > Java > Compiler > Errors/Warnings
) - not preferable
As per your update: having 0 warnings is not a goal you should set. The number of warnings depends on the settings, so if you don't all have unified IDEs, this number will vary. And then you can add checkstyle / PMD to report warnings as well - then you'll have even more. The reasonable behaviour is to have a warnings treshold.
If you don't want anyone to delete this method, just add a comment:
// This method is used is used by JNI. (Don't delete)
Somewhere else in the class:
if(Boolean.FALSE.booleanValue())
{ // prevents warning for unused private method which is used from JNI
someMethodCalledOnlyFromJNI();
}
(can't use simple false
because that results in dead code warning).
Either just ignore the warning, or declare it as protected
instead. If you go for protected
and want to prevent subclassing/overriding as well, then declare it final
as well.
To start with, its only a warning, thus it should not be an issue for you.
You could either mod the code to remove that function thus removing the problem.
Or just call it from some where at the start/end of your code and ignore any results. As long as it is not going to try to set up any thing that will affect the rest of your program you will be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With