title: how to set default value for string variable in groovy
body: <p>I have the following function defined in groovy</p>
  
  <pre><code>def deploy_app(Map InputParameters, List OptionalParameters = []) {
      String InputParametersString = InputParameters.inject([]) { acc, val -&gt; acc + "--set ${val.getKey()}=${val.getValue()}" }.join(" ")
      .
      .
      .
  }
  </code></pre>
  
  <p>What i want to do is be able to have the map <code>InputParameters</code> parameter to have default value of empty map AND also for the string <code>InputParametersString</code> to have a default value of empty string if <code>InputParameters</code> parameter is not passed or is empty.</p>
  
  <p>Here is what i have tried using <strong>elvis operator</strong> but not working </p>
  
  <pre><code>def deploy_app(Map InputParameters = [:], List OptionalParameters = []) {
      String InputParametersString = "" ?: InputParameters.inject([]) { acc, val -&gt; acc + "--set ${val.getKey()}=${val.getValue()}" }.join(" ")
      .
      .
      .
  }
  </code></pre>
  
  <p>also tried this</p>
  
  <pre><code>def deploy_app(Map InputParameters = [:], List OptionalParameters = []) {
      String InputParametersString = InputParameters.inject([]) { acc, val -&gt; acc + "--set ${val.getKey()}=${val.getValue()}" }.join(" ") ?: ""
      .
      .
      .
  }
  </code></pre>
  
  <p>So how do i do this so that when no <code>InputParameters</code> is passed, i am able to have the string <code>InputParametersString</code> as empty string value?</p>
  
  <p>thanks</p>