Java Reference
In-Depth Information
Point[] p = new Point[100];
for (int i = 0; i < p.length; i++) {
p[i] = new Point();
p[i].move(i, p.length-1-i);
}
}
}
Inlining the method move of class Point in method main would transform the for loop to
the form:
for (int i = 0; i < p.length; i++) {
p[i] = new Point();
Point pi = p[i];
int j = p.length-1-i;
pi.x += i;
pi.y += j;
}
The loop might then be subject to further optimizations.
Such inlining cannot be done at compile time unless it can be guaranteed that Test and
Point will always be recompiled together, so that whenever Point - and specifically its
move method - changes, the code for Test.main will also be updated.
8.4.3.4. native Methods
A method that is native is implemented in platform-dependent code, typically written in an-
other programming language such as C. The body of a native method is given as a semicolon
only, indicating that the implementation is omitted, instead of a block.
For example, the class RandomAccessFile of the package java.io might declare the fol-
lowing native methods:
Click here to view code image
package java.io;
public class RandomAccessFile
implements DataOutput, DataInput {
. . .
public native void open(String name, boolean writeable)
throws IOException;
public native int readBytes(byte[] b, int off, int len)
throws IOException;
public native void writeBytes(byte[] b, int off, int len)
throws IOException;
public native long getFilePointer() throws IOException;
Search WWH ::




Custom Search