When a Java system property is set on the command line without value ("-Dkey"), what value does it get?

StackOverflow https://stackoverflow.com/questions/23269994

  •  08-07-2023
  •  | 
  •  

Frage

According to the Oracle documentation, I can set system properties of a Java process on the command line with the following syntax:

-Dproperty=value

But what happens when I don't specify the value, i.e. when I omit the "equals value" part:

-Dproperty

What value will the system property be set to? true? An empty string? Or any string with an undefined, implementation specific value?

War es hilfreich?

Lösung

It will return an empty string. According to System.getProperty(String key) null is returned only if there is no property with that key. So if we define a propety with -D it exists in the system

Andere Tipps

From simple trials with a Oracle HotSpot VM, I can see that system properties set on the command line without value get an empty string as value.

However this is only a partial answer to the question. A link to the some specification would be a better answer.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top