How to provide preprocessor directives in Java

Robert H picture Robert H · Dec 12, 2013 · Viewed 39.4k times · Source

How can I correctly provide the following functionally from C# in Java?

[C#]

#define PRODUCTION //Change from sandbox to production to switch between both systems.

#if SANDBOX
    using NetSuite.com.netsuite.sandbox.webservices;
#endif

#if PRODUCTION
    using NetSuite.com.netsuite.webservices;
#endif

Answer

Tim B picture Tim B · Dec 12, 2013

Java doesn't have a preprocessor - so the simple answer is that you can't.

This sort of thing is normally handled in Java using Dependency Injection - which is both more powerful and more flexible.

http://www.vogella.com/articles/DependencyInjection/article.html