java.io.File.LazyInitialization

Alex Lam S.L. alexlamsl at gmail.com
Sat Jan 21 18:11:46 UTC 2012


Hi there,

Whilst reading the JDK6 source code for java.io.File.createTempFile(),
I noticed that:

...
  private static class LazyInitialization {
...
  static final String temporaryDirectory = temporaryDirectory();
  static String temporaryDirectory() {...}
...
  }
...
  public static File createTempFile(String prefix, String suffix, File
directory) throws IOException {
...
    if (directory == null) {
      String tmpDir = LazyInitialization.temporaryDirectory();
...

Shouldn't the last line use the static field instead of the static method?

The static field "temporaryDirectory" is not used anywhere else in the
class, which also make this seem suspicious.


Alex.



More information about the core-libs-dev mailing list