Complaints I'm Seeing About Java
dlweinreb.wordpress.com
dlweinreb.wordpress.com
I guess most people don't need to do that anymore.
char bytes[]={0,1,0,0};
MyStruct *myStruct=((MyStruct [asterisk] )bytes);
...myStruct->a is now 256.
How do you format code here?
Presumably what you want can be achieved with ByteArrayInputStream and DataInputStream.
byte[] bytes = {0,1,0,0};
DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
int a = in.readInt();
in.close();
untested, but something like that... There is also object serialization. I never had a use case for what you describe. (format code with 4 leading spaces)
Anyway, no doubt that you can write faster code in C, but I am glad that I did not have to look at pointer arithmetic for the last 8 years. Using your array->struct technique would be a major headache if the struct get's more complex.
Indent at least two spaces for code.
Most people who want that much control use C or C++.
for example, to convert an unsigned byte to an integer:
byte a = (some unsigned byte data);
int b = 0xff & a;From this list I would like to have this: - A short cut syntax to declare getters and setters. - A shorter syntax to use "functions as objects". - Easier to use stream classes.
I needed to construct a bunch of polynomials from a set of 20 odd coordinates (x,y) coordinates. I decided to use langrange interpolating polynomials, and I wanted the polynomial to match three of the twenty points (otherwise they bounce all over the place). The idea was then to select the polynomial that minimized the least squares difference with the other points that weren't used to create the curve(I'm not sure if this counts as practical, since there are other approaches to polynomial curve-fitting that would have been more appropriate). Anyway, I had a method that evaluated the least squares, and then I constructed the polynomial as a block of code and yielded to it in the iteration that evaulated all the point for the least-squares fit...
There are other ways to do it (always are) - I could have broken the polynomials into terms and reconstructed them in the method, for instance - but block and yield were very convenient in this case.