Q:

Retrieving an array element in Scala

I am calling a method that returns an array:
val localTrustManagerFactory =
  TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm)
val localTrustManager =
  ((localTrustManagerFactory.getTrustManagers).apply(0)).asInstanceOf[X509TrustManager]

If I leave out the .apply call, I get a compile-time error:
val localTrustManager =
  ((localTrustManagerFactory.getTrustManagers)(0)).asInstanceOf[X509TrustManager]
error: too many arguments for method getTrustManagers: ()Array[javax.net.ssl.TrustManager]

Is there any better way to retrieve an array element? I though that the compiler would supply the apply method call implicitly.
UPDATE: The classes used in this code are from the standard Java library:
import javax.net.ssl.TrustManagerFactory
import javax.net.ssl.X509TrustManager

I don't know if the Scala compiler (2.9.2-1) interprets getTrustManagers as having an argument list or not.

A:

Your method getTrustManagers seems to be defined with an empty argument list, that is
def getTrustManagers(): Array[TrustManager]

rather than with no argument list
def getTrustManagers: Array[TrustManager]

What you have is a corner case, scala tries to be flexible as to dropping the empty argument list at call site, but it could be ambiguous if the apply was dropped at the same time (e.g, if there was an apply method with no argument, or if getTrustManagers was overloaded and had a version with one argument). 
You can do getTrustManagers()(0) (same as in java, except for the (0) instead of [0].

