Alex Rivera | Logout

Why doesn't Java have constants for well-known system property names?

Asked 2009-04-23T00:32:17.540
16

The java.lang.System class defines a number of well-known properties.

For example, you can obtain the JVM's temporary directory by looking up the "java.io.tmpdir" property:

... = System.getProperty("java.io.tmpdir");

What I don't understand is why these properties aren't defined as constants (e.g. in the java.lang.System class). This would be a lot less error-prone than using literal Strings. In other words, I would like to be able to do this:

... = System.getProperty(System.JAVA_IO_TMPDIR);

Any ideas why this wasn't done? It could even be added in a future release of Java without breaking backward compatibility. Or am I missing something obvious?

Edit
Report

1 Answer

9

My guess is that Sun did not want to commit to a predefined set of system properties. If they are not defined as contants they can add system properties at any time (even if they only release an incremental version of the JDK like from 1.4.1 to 1.4.2).

Edit:
Any predefined constants must be considered part of the API. Thus even changing the number of constants is an API change. By not defining any constants Sun is allowed to define new system properties without introducing an API change.

answered 2009-04-23T00:44:21.287

Your Answer