There is no direct equivalent. As mentioned, enums can be used to fill one of #define's roles. (enumerated values)
public static final constant member variables can fulfill another. (named constants)
And actually, if I understand correctly, #define is not part of the C language per se, but belongs in the realm of the preprocessor, and you can run Java code through a c preprocessor.
EDIT: Yeah, you can:
:; cat X.java
#define blah int
public class X {
Y y;
blah x;
}
jeff@shiro:/tmp 14:33:34
:; cpp -P !$
cpp -P X.java
public class X {
Y y;
int x;
}
Message was edited by:
jverd
> What would this declaration be in java:
>
> #defineSTRAIGHT_FLUSH1
You would declare,
public static final int STRAIGHT_FLUSH = 1;
in a class. Or you could be more OO and declare an enum, like
public enum Hands {STRAIGHT_FLUSH, PAIR, FLUSH /* etcetera */}
> #defineRANK(x)((x >> 8) & 0xF)
Are you translating C into Java? (I think I just spit up in my mouth a little.)
You will have to turn that into a method or two:
public static int rank(int x) {
return (x>>8) & 0xf;
}
You may want to have versions that take x's of type other than int -- long?
And I'm guessing about the returm type. Return type byte could be
more appropriate, for example.
Dr - yes I am, I am just mucking around with a couple of card games... I was implementing something that I had written, and then of course ran across something that was much more efficient but only available in c so I thought I would have a go at converting it... you know, just to see, and I wanted to see how much faster and more efficient it was... haha