Sunday, July 12, 2009

How do we make (#define) in Java ?

In C++, we use #define to define macros. How can we do it in Java ?


Can it be used as function like in C++? (for example : #define square(x)=(x)*(x) )

How do we make (#define) in Java ?
The define statment is a preprocessor statment that replace an argument with another argument.usually after #import.


I'll explain in C


EG.


#define print printf


#define x 16


#define y a+x


The complier find those argument that matches and convert them into the constant/alogrithm/string that was #define.


The closest that I can come to making a define statment in java is


private static final (int,long) that cause the agrument to be a contstant.


I use a class to provide for the alogrithm though.


If you know how to #define in java Please add in Details :)
Reply:you need an external preprocessor to be able to define in java. Report It



No comments:

Post a Comment