How to fulfill contract across two different Java versions?

S

Scott Simpson

How do I fulfill a contract across two different Java versions? That is, how
do I make the code that implements my contract portable.

Specifically, I have a class that implements the interface
java.sql.Connection. The code is written for JDK 1.3. In JDK 1.4 they added
some functions like prepareStatement(String,String[]) and savepoint(). If I
try to compile under JDK 1.4 it breaks because I don't have all the
functions for the interface contract defined.

I was hoping there might be some type of "prototype" object I could inherit
from to solve this problem. This prototype object would be portable across
versions and would fill in any methods I didn't write myself.

Thanks for any help.
 
A

Andrew McDonagh

Scott said:
How do I fulfill a contract across two different Java versions? That is, how
do I make the code that implements my contract portable.

Specifically, I have a class that implements the interface
java.sql.Connection. The code is written for JDK 1.3. In JDK 1.4 they added
some functions like prepareStatement(String,String[]) and savepoint(). If I
try to compile under JDK 1.4 it breaks because I don't have all the
functions for the interface contract defined.

I was hoping there might be some type of "prototype" object I could inherit
from to solve this problem. This prototype object would be portable across
versions and would fill in any methods I didn't write myself.

Thanks for any help.

If you don't need those methods when your app is run with the 1.3 jre,
then why not simply create them anyway. They will just be unused(i.e.
not called) with the 1.3 jre cause it doesn't know about them via its
interface. The 1.4 jre will/may call them, but if your implementation
doesn't do anything, then everything will be ok.

Remember Interfaces specify what methods must be available upon a given
object, but there is nothing stopping you adding additional methods.
They just aren't visible when referencing the object via the interface type.
 
S

Scott Simpson

Andrew said:
If you don't need those methods when your app is run with the 1.3 jre,
then why not simply create them anyway. They will just be unused(i.e.
not called) with the 1.3 jre cause it doesn't know about them via its
interface. The 1.4 jre will/may call them, but if your implementation
doesn't do anything, then everything will be ok.

Remember Interfaces specify what methods must be available upon a given
object, but there is nothing stopping you adding additional methods.
They just aren't visible when referencing the object via the interface
type.

I thought about this too and was going along this path until I ran into a
small problem. One of the functions returns a new type: Savepoint. Now I
can't define the Savepoint manually for JDK 1.3 and then have it ignored in
JDK 1.4. Now what?
 
T

tzvika.barenholz

It's their mess to begin with for breaking your code.
I'd seriously look into moving on from 1.3 , since 1.5 is almost out...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top