Al2O3
Al2O3

Reputation: 3213

Java interface's deprecated methods must be implemented or not?

I am updating HBase code of 0.98.10 to 1.1.5, but the complier shows that myWalObserver doesn't implement the original interface WALObserver anymore.

The compiler outputs:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-
plugin:3.1:compile (default-compile) on project observer: Compilation failure
[ERROR] /Users/zhangsong.zs/git/HBaseObserver/src/main/java/com/gavin/observer/
DataSyncWALObserver.java:[39,8] com.gavin.observer.DataSyncWALObserver
 is not abstractand does not override abstract method  
postWALWrite(org.apache.hadoop.hbase.coprocessor.ObserverContext<? extends org.apache.hadoop.hbase.coprocessor.WALCoprocessorEnvironment>,
org.apache.hadoop.hbase.HRegionInfo,org.apache.hadoop.hbase.wal.WALKey,
org.apache.hadoop.hbase.regionserver.wal.WALEdit) in 
org.apache.hadoop.hbase.coprocessor.WALObserver

So some new APIs have been added in the same interface of 1.1.5 version, and the old APIs are deprecated. The old code does not work any more, which is bad for developers.

So I want to ask: must I still implement the old interface methods which are already deprecated or not?

Upvotes: 0

Views: 1907

Answers (3)

Gaurava Agarwal
Gaurava Agarwal

Reputation: 984

It is code maintenance technique.

  1. Deprecated methods are part of class/interface.
  2. You can choose to throw exception inside such method in derived class.

Here is some background:

  1. Generally if the Interface function is found redundant/unusable then it is marked deprecated.
  2. We can choose how to process Deprecated annotation compilation/error reporting in your IDE.

Upvotes: 0

glee8e
glee8e

Reputation: 6419

Yes, you must. Deprecated means it's not suggested to use. Any implementation must still implement it.

Upvotes: 1

C. K. Young
C. K. Young

Reputation: 223123

Yes, you must implement deprecated interface methods. However, you are allowed to make them throw UnsupportedOperationException to signal to callers that they're not actually implemented.

Upvotes: 5

Related Questions