public static void main(string[] args) throws ioexception {
@cleanup inputstream in = new fileinputstream(args[0]);
@cleanup outputstream out = new fileoutputstream(args[1]);
byte[] b = new byte[1024];
while (true) {
int r = in.read(b);
if (r == -1) break;
out.write(b, 0, r);
}
}
实际效果相当于:
public static void main(string[] args) throws ioexception {
inputstream in = new fileinputstream(args[0]);
try {
outputstream out = new fileoutputstream(args[1]);
try {
byte[] b = new byte[10000];
while (true) {
int r = in.read(b);
if (r == -1) break;
out.write(b, 0, r);
}
} finally {
if (out != null) {
out.close();
}
}
} finally {
if (in != null) {
in.close();
}
}
}
public class sneakythrows implements runnable {
@sneakythrows(unsupportedencodingexception.class)
public string utf8tostring(byte[] bytes) {
return new string(bytes, "utf-8");
}
@sneakythrows
public void run() {
throw new throwable();
}
}
实际效果相当于:
public class sneakythrows implements runnable {
@sneakythrows(unsupportedencodingexception.class)
public string utf8tostring(byte[] bytes) {
try{
return new string(bytes, "utf-8");
}catch(unsupportedencodingexception uee){
throw lombok.sneakythrow(uee);
}
}
@sneakythrows
public void run() {
try{
throw new throwable();
}catch(throwable t){
throw lombok.sneakythrow(t);
}
}
}
public class synchronized {
private final object readlock = new object();
@synchronized
public static void hello() {
system.out.println("world");
}
@synchronized
public int answertolife() {
return 42;
}
@synchronized("readlock")
public void foo() {
system.out.println("bar");
}
}
实际效果相当于:
public class synchronized {
private static final object $lock = new object[0];
private final object $lock = new object[0];
private final object readlock = new object();
public static void hello() {
synchronized($lock) {
system.out.println("world");
}
}
public int answertolife() {
synchronized($lock) {
return 42;
}
}
public void foo() {
synchronized(readlock) {
system.out.println("bar");
}
}
}