Accessing a Scala object from Java code -
i trying use scala class has default argument:
object simplecredstashclient { def apply(kms: awskmsclient, dynamo: amazondynamodbclient, aes: aesencryption = defaultaesencryption) ... } when try instantiate instance of class java, error:
error:(489, 43) java: cannot find symbol symbol: method simplecredstashclient(com.amazonaws.services.kms.awskmsclient,com.amazonaws.services.dynamodbv2.amazondynamodbclient) location: class com.engineersgate.build.util.credentialsutil
defaultaesencryption scala object. how access scala object in java?
default arguments become synthetic methods of form <meth>$default$<idx>(). further, instances of object a may found @ a$.module$ (if a top-level object), or @ outer.a() (if a defined class o { object }).therefore, there 2 ways this:
direct usage of object:
simplecredstashclient.apply( kms, dynamo, defaultaesencryption$.module$ ); default argument:
simplecredstashclient.apply( kms, dynamo, simplecredstashclient.apply$default$3() ); the first 1 looks better, if default argument ever changes, you'll have update code too. in second one, argument whatever default argument is, , break if argument stops having default, or changes index. scala uses second method when compiled.
Comments
Post a Comment