I'm importing a class which has been deprecated, which I'm forced to use.
I want to suppress the deprecated error using the @SuppressWarnings("deprecation")
annotation.
As per the comment on that annotation:
As a matter of style, programmers should always use this annotation on the most deeply nested element where it is effective. If you want to suppress a warning in a particular method, you should annotate that method rather than its class.
So I clearly don't want to annotate the class and thus suppress deprecation warnings on any type my class uses, but I also would like to use the import
statement to avoid typing out the fully qualified type name, which spans my entire monitor, on each use of the deprecated class.
I think I want to do something like annotating the import
statement with @SuppressWarnings
(NOT POSSIBLE) or specifying in the @SuppressWarnings
annotation which type to ignore warnings for (e.g. @SuppressWarnings("deprecation", "fully.qualified.type.name")
.
I want to indicate to the compiler "it's okay if I use this one, and only this one, deprecated class, referenced by its Simple Name, anywhere within this other class, and any other deprecated classes I reference you should let me know about".
Is there anything like this available?
Place the @SuppressWarnings annotation at the declaration of the class, method, field, or local variable that uses a deprecated API. The @SuppressWarnings options are: @SuppressWarnings("deprecation") — Suppresses only the ordinary deprecation warnings.
Use warnings. filterwarnings() to ignore deprecation warnings Call warnings. filterwarnings(action, category=DeprecationWarning) with action as "ignore" and category set to DeprecationWarning to ignore any deprecation warnings that may rise.
Follow the steps at https://flutter.dev/go/android-project-migration to migrate your project. You may also pass the --ignore-deprecation flag to ignore this check and continue with the deprecated v1 embedding.
Instead of a single statement, you can also mark a function, a class or a file ( @file:Suppress("DEPRECATION") in its beginning) with the annotation to suppress all the deprecation warnings issued there. In IntelliJ IDEA this can also be done through Alt + Enter menu with caret placed on code with deprecation warning.
A way to work around this would be to do the following, assuming you can extend the Deprecated class.
import comp.DeprecatedClass;
@SuppressWarnings("deprecation") public class MyDeprecatedClass extends DeprecatedClass{ }
Then you can use your version without having to worry about warnings.
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