Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide preprocessor directives in Java

CHow 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 
like image 758
Robert H Avatar asked Dec 12 '13 14:12

Robert H


People also ask

How do you create a preprocessor in Java?

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.

How do you write a preprocessor directive?

Examples of some preprocessor directives are: #include, #define, #ifndef etc. Remember that the # symbol only provides a path to the preprocessor, and a command such as include is processed by the preprocessor program. For example, #include will include extra code in your program.

What is preprocessor directive in Java?

Preprocessor directives are lines included in a program that begin with the character #, which make them different from a typical source code text. They are invoked by the compiler to process some programs before compilation.

Can I use #define in Java?

Java doesn't have a general purpose define preprocessor directive. private static final int PROTEINS = 100; Such declarations would be inlined by the compilers (if the value is a compile-time constant).


2 Answers

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

like image 93
Tim B Avatar answered Sep 20 '22 15:09

Tim B


Java doesn't have a preprocessor, yet that doesn't mean that you can't run Java code through cpp - though it would not be supported by any tools, AFAIK.

like image 25
Ingo Avatar answered Sep 20 '22 15:09

Ingo