It is just getting a system property. Retrieving system properties requires permissions which the calling code may not have. The doPrivileged
asserts the privileges of the calling class irrespective of how it was called. Clearly, doPrivileged
is something you need to be careful with.
The code quoted is the equivalent of:
String lineSeparator = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<String>() {
public String run() {
return System.getProperty("line.separator");
}
}
);
(Don't you just love the conciseness of Java's syntax?)
Without asserting privileges, this can be rewritten as:
String lineSeparator = System.getProperty("line.separator");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…