Reputation: 12031
I have an interface with a deprecated method:
public interface A
{
@Deprecated
public String getUUID();
}
And another interface with the same but non-deprecated method:
public interface B
{
public String getUUID();
}
A class that implements both interfaces:
public class MyBean implements A, B
{
@Override
public String getUUID()
{
return UUID.randomUUID().toString();
}
}
There is a warning during the compilation of MyBean
:
javac -Xlint:deprecation MyBean.java A.java B.java
MyBean.java:8: warning: [deprecation] getUUID() in A has been deprecated
public String getUUID()
^
1 warning
I cannot really understand why is this warning necessary when I implement B
which defines the non-deprecated method...
Upvotes: 4
Views: 299
Reputation: 310985
The implementation you've provided satisfies both interfaces, so anything that applies to either of them applies to the implementation as well. There's no reason to single out B as the only one that applies. If you don't want A, don't implement it.
Upvotes: 0
Reputation: 95978
You already answered your question.
You get the warning because you do implement A
, which has the @Deprecated
annotation. See here:
@Deprecated annotation indicates that the marked element is deprecated and should no longer be used. The compiler generates a warning whenever a program uses a method, class, or field with the @Deprecated annotation.
I don't see anything wrong with that warning. It should be there as you are really implementing a Deprecated method that's found in one of the interfaces you're implementing.
Upvotes: 3