File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes deprecated interface methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "deprecated interface methods" Watch "deprecated interface methods" New topic
Author

deprecated interface methods

damian cosmos
Ranch Hand

Joined: Dec 13, 2001
Posts: 32
Hi all,
If you are implementating an interface that has deprecated methods, is it possible to compile this code without having deprecation errors ?
Any help would be appreciated.
Regards,
Damian.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I don't see how. If you are implementing the interface then you are agreeing to provide implementations for all of the methods that it requires. Of course, your actual method implementations don't have to do much and you don't really have to use them.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
damian cosmos
Ranch Hand

Joined: Dec 13, 2001
Posts: 32
Hi Dirk,
I apologise, I made a mistake. I meant deprecation warnings instead of deprecation errors at the end of my initial post.
Is it possible to stop there warnings from coming up when you compile ?
Regards,
Damian.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Why do they bother you?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Yes, there is! Make your implementation deprecated, too. Only non-deprecated methods cause warnings if they rely on deprecated api.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
damian cosmos
Ranch Hand

Joined: Dec 13, 2001
Posts: 32
Hi Ilja,
How would you make your implementation deprecated if your interface had deprecated and non-deprecated methods ?
Regards,
Damian.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Make only the deprecated methods deprecated?
Say you have to implement the following interface:

So, method2() is deprecated in the interface, therefore mark your implementation of method2 as deprecated, too:

Doing this, you shouldn't get any deprecated warning for the declaration of method2.
damian cosmos
Ranch Hand

Joined: Dec 13, 2001
Posts: 32
Hi Ilja,
I added the @deprecated javadoc comment to all of the overridden deprecated
methods but to no avail...
Compiling HttpSessionImpl.java with this command:
javac -deprecation HttpSessionImpl.java
results in this output:

HttpSessionImpl.java:16: warning: javax.servlet.http.HttpSessionContext in
javax.servlet.http has been deprecated
import javax.servlet.http.HttpSessionContext;
^
HttpSessionImpl.java:57: warning: javax.servlet.http.HttpSessionContext in
javax.servlet.http has been deprecated
public HttpSessionContext getSessionContext() {
^
HttpSessionImpl.java:18: warning: removeValue(java.lang.String) in
javax.servlet.http.HttpSession has been deprecated
public class HttpSessionImpl implements HttpSession
^
HttpSessionImpl.java:18: warning:
putValue(java.lang.String,java.lang.Object) in
javax.servlet.http.HttpSession has been deprecated
public class HttpSessionImpl implements HttpSession
^
HttpSessionImpl.java:18: warning: getValueNames() in
javax.servlet.http.HttpSession has been deprecated
public class HttpSessionImpl implements HttpSession
^
HttpSessionImpl.java:18: warning: getValue(java.lang.String) in
javax.servlet.http.HttpSession has been deprecated
public class HttpSessionImpl implements HttpSession
^
HttpSessionImpl.java:18: warning: getSessionContext() in
javax.servlet.http.HttpSession has been deprecated
public class HttpSessionImpl implements HttpSession
^
7 warnings
Any help would be gratly appreciated.
Regards,
Damian.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Mhh, strange - for me generally it works. Can you post the source code?
damian cosmos
Ranch Hand

Joined: Dec 13, 2001
Posts: 32
Ilja,
Here it is:
/**
* This class contains a bare-bones implementation of the HttpSesion interface
* It can be useful when testing a Servlet as an application, where you don't
* have access to a real HttpSession object (e.g. as implemented by Tomcat).
*
* For an example: see the main() method in com.digisoft.util.controller.servlet.GetSessionParams
*
* Unfortunately ... it gives deprecation warnings when compiled ... there's not much
* that can be done about this
*/
package com.digisoft.testing;
import java.util.Hashtable;
import javax.servlet.http.HttpSession;
import java.util.Enumeration;
import javax.servlet.http.HttpSessionContext;
public class HttpSessionImpl implements HttpSession
{
Hashtable attributeTable = new Hashtable();
public HttpSessionImpl()
{
attributeTable = new Hashtable();
}
public Object getAttribute(String name)
{
return attributeTable.get(name);
}
public void setAttribute(String name, Object value)
{
attributeTable.put(name, value);
}
public long getCreationTime() {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method getCreationTime() not yet implemented.");
}
public String getId() {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method getId() not yet implemented.");
}
public long getLastAccessedTime() {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method getLastAccessedTime() not yet implemented.");
}
public void setMaxInactiveInterval(int interval) {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method setMaxInactiveInterval() not yet implemented.");
}
public int getMaxInactiveInterval() {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method getMaxInactiveInterval() not yet implemented.");
}
/**
* @deprecated
*/
public HttpSessionContext getSessionContext() {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method getSessionContext() not yet implemented.");
}
public Object getValue(String name) {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method getValue() not yet implemented.");
}
public Enumeration getAttributeNames() {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method getAttributeNames() not yet implemented.");
}
public String[] getValueNames() {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method getValueNames() not yet implemented.");
}
public void putValue(String name, Object value) {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method putValue() not yet implemented.");
}
public void removeAttribute(String name) {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method removeAttribute() not yet implemented.");
}
public void removeValue(String name) {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method removeValue() not yet implemented.");
}
public void invalidate() {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method invalidate() not yet implemented.");
}
public boolean isNew() {
/**@todo: Implement this javax.servlet.http.HttpSession method*/
throw new UnsupportedOperationException("Method isNew() not yet implemented.");
}
public static void main(String[] args)
{
HttpSessionImpl httpSessionImpl1 = new HttpSessionImpl();
}
}
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
The following fixes most of them for me:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: deprecated interface methods