Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore Deprecated Type Warnings on import Statement

Tags:

java

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?

like image 299
Tom Tresansky Avatar asked Dec 12 '11 16:12

Tom Tresansky


People also ask

How do you stop a deprecated warning?

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.

How do I stop deprecation warning in Python?

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.

How do you ignore deprecation warnings in flutter?

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.

How do you stop deprecation warning in Kotlin?

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.


1 Answers

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.

like image 174
Jyro117 Avatar answered Nov 05 '22 10:11

Jyro117