Java标准注释

Java标准注释,java,eclipse,Java,Eclipse,我最近开始阅读注释。我在这里弃用了armStrong()方法,我需要抑制弃用警告,但无论我放在哪里,它都会显示“不必要的@SuppressWarnings(“弃用”)” 有人能告诉我应该把它放在哪里,这样方法就不推荐了警告就不会再出现了吗 import java.io.*; import java.lang.annotation.*; import java.lang.reflect.Method; @Retention(RetentionPolicy.RUNTIME) @interface

我最近开始阅读注释。我在这里弃用了armStrong()方法,我需要抑制弃用警告,但无论我放在哪里,它都会显示“不必要的@SuppressWarnings(“弃用”)”

有人能告诉我应该把它放在哪里,这样
方法就不推荐了
警告就不会再出现了吗

import java.io.*;
import java.lang.annotation.*;
import java.lang.reflect.Method;

@Retention(RetentionPolicy.RUNTIME)

@interface number
{
String arm();
}

public class Ch10LU2Ex4
{  
@Deprecated
@number(arm = "Armstrong number")
public static void armStrong(int n)
 {
    int temp, x, sum = 0;
    temp = n;
    while(temp!=0)
     {
        x = temp%10;
        sum = sum+x*x*x;
        temp = temp/10;
     }
    if(sum==n)
     {
        System.out.println("It is an armstrong number");
     }
    else
    {
        System.out.println("It is not an armstrong number");
    }
 }

public static void main(String[] args) 
  {

    try
    {   
        Ch10LU2Ex4 obj = new Ch10LU2Ex4();
        obj.invokeDeprecatedMethod();
        Method method = obj.getClass().getMethod("armStrong", Integer.TYPE);
        Annotation[] annos = method.getAnnotations();
        for(int i = 0; i<annos.length; i++)
        {
            System.out.println(annos[i]);
        }
    }
    catch(Exception e)
     {
        e.printStackTrace();
     }
  } 
    @SuppressWarnings("deprecation")
    public void invokeDeprecatedMethod()
    {
        try
        {
        System.out.println("Enter a number between 100 and 999:");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        Ch10LU2Ex4.armStrong(x);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }
  }  
import java.io.*;
导入java.lang.annotation.*;
导入java.lang.reflect.Method;
@保留(RetentionPolicy.RUNTIME)
@接口号
{
弦臂();
}
公共类Ch10LU2Ex4
{  
@不赞成
@编号(arm=“阿姆斯特朗编号”)
公共静态无效阿姆斯特朗(int n)
{
内部温度,x,总和=0;
温度=n;
while(温度!=0)
{
x=温度%10;
总和=总和+x*x*x;
温度=温度/10;
}
如果(总和=n)
{
System.out.println(“这是一个阿姆斯特朗号码”);
}
其他的
{
System.out.println(“它不是阿姆斯特朗号码”);
}
}
公共静态void main(字符串[]args)
{
尝试
{   
Ch10LU2Ex4 obj=新的Ch10LU2Ex4();
obj.invokedeprocartedmethod();
方法Method=obj.getClass().getMethod(“armStrong”,Integer.TYPE);
Annotation[]annos=method.getAnnotations();

对于(int i=0;i,使用另一种方法中不推荐的方法会导致警告

典型用法如下所示:

 @SuppressWarnings("deprecation")
 public void invokeDeprecatedMethod() {
     instanceofotherclass.armStrong(1);
 }

在同一个类中,假定程序员知道自己在做什么。

这就是。从该类本身调用类的已弃用方法时,不需要使用
@SuppressWarnings
,因为这样的调用一开始不会生成弃用警告。从其他类调用已弃用方法s将需要
@SuppressWarnings
注释。

您将该注释放置在何处?我将其放置在许多位置,但它在任何地方都不起作用,因此我只是将其删除。这没有帮助。@Robin..只需在调用不推荐使用的方法的位置使用它即可。