我最近开始阅读注释。我在这里弃用了 armStrong() 方法,我需要抑制弃用警告,但无论我把它放在哪里,它都会说“不必要的@SuppressWarnings(“deprecation”)”。
谁能告诉我把它放在哪里,这样method is deprecated
警告就不会再出现了?
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();
}
}
}