title: Why accessing to groovy map through variable in parentheses always returns null?
body: <h2>Brief</h2>
  
  <p>I need null-safe access to map/property by dynamic name of the key. Map can be null itself. I've came up with <code>map?.(keyName)</code> but wonder why it works not as expected and returns always <code>null</code></p>
  
  <h2>Code sample</h2>
  
  <pre><code>def map = [key: 'value']
  def keyName = 'key'
  
  map.each({ key, value -&gt; println("[${key.class}]: [${value.class}]")})
  println("keyName class is [${keyName.class}]")
  
  println(map?.(keyName))                        // null  &lt;--------- My question
  
  // Alternatives that work well
  println(map?.(keyName as String))              // value
  println(map?.(keyName as java.lang.String))    // value
  println(map?.get(keyName))                     // value
  
  ​
  </code></pre>
  
  <p><em>Output</em></p>
  
  <pre><code>[class java.lang.String]: [class java.lang.String]
  keyName class is [class java.lang.String]
  null
  value
  value
  value
  </code></pre>
  
  <h2>Question</h2>
  
  <p>If both <code>keyName</code> and map keys are of type <code>java.lang.String</code> why <code>map?.(keyName)</code> does not return value? Why <code>map?.(keyName as String)</code> returns?
     ​</p>
  
  <h1>Links</h1>
  
  <p>Checked in <a href="https://groovyconsole.appspot.com" rel="nofollow noreferrer">Groovy web console</a></p>