Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java conditional imports

Tags:

java

How to have conditional imports in Java like we have the ifdefs in C This is what I intend to achieve

ifdef TEST
import com.google.mystubs.swing;
elif
import javax.swing.*;
endif
like image 838
user1495174 Avatar asked Jul 02 '12 05:07

user1495174


1 Answers

You don't have conditional import with java

But you could conditionally use different classes with same name using fully qualified name

for example:

if(useSql){
  java.sql.Date date = new java.sql.Date()
}else{
  java.util.Date date = new java.util.Date()
}
like image 84
jmj Avatar answered Nov 08 '22 01:11

jmj