1

I am using a library from others, which i cannot change. Now I found one API has been changed.

Previous version 1:

int api_it(int a, int b)

The new version 2:

int api_it(int a, int b, int c, int d)

I was asked to support both versions. I thought I could use this (I am still using the previous jar file),

if( version == 1 )
    api_it(a, b);
else
    api_it(a,b,0,0); 

There is the compile error for sure. I thought it not possible to include 2 versions of same library.

Is there any way to solve it? Any suggestion would be appreciated. Thanks!

Simon chen
  • 21
  • 2

1 Answers1

1

Basically java doesn't support conditional compilation like , C++ does like in C++,

#define Version2
#ifdef Version2
  //Call version 2 function
#ifdef Version1
  //Call version 1 function

But there is one concept call Optimization you can use it following are some links that helps you on same. Java conditional compilation: how to prevent code chunks to be compiled?

Conditional compile

Conditional Compilation In Java

Community
  • 1
  • 1
Santosh Dhanawade
  • 1,756
  • 14
  • 29
  • Thank you! Maybe I was not clear for the question. I need to check the target version at run-time. Finally, I solved it by java reflection. – Simon chen Oct 14 '13 at 06:33