problem when converting a .const file (c++) to .java class
I have a .const file, lets say abc.const (a cpp file). the contents of that file is,
xyz :ullong:0x1000000000000000ULL yub :ullong:0x0100000000000000ULL .... ....
now i ve a program to convert this file to .java class.
But when i try above,
i got the following error
abc.java:255: ';' expected public static final long xyz = 0x1000000000000000ULL;
ho开发者_C百科w should i resolve this. thanks in advance??
( i need to generate a .java class from this .const file by solving this )
- There are no unsigned types in Java, so there's no "U" numeric literal specifier
- You only use a single L for a long in Java, which is always 64 bits
- You appear to have two leading 0s before the x.
So the Java would be:
public static final long xyz = 0x1000000000000000L;
Note that this won't be an exact equivalent of the C++, due to Java not having unsigned types as mentioned before. If you need to represent values larger than Long.MAX_VALUE
, you should use the BigInteger
class. If you're find with the restricted range of long
, you're better off sticking with the primitive type.
There is no Java equivalent to an unsigned long long
If you need a number that large, you're going to have to use the BigInteger
class:
http://download.oracle.com/javase/6/docs/api/java/math/BigInteger.html
That being said, the max value for a java long
is 2^63-1. If that's big enough for you just change
0x100000000000000ULL
to
0x100000000000000L
精彩评论