How to access object with "creative" names in scala? -


for example, given

object ~ {    def foo = ??? } 

how access method?

neither of work:

~.foo    `~`.foo 

with both compiler complains "illegal start of simple expression".

and yes, know shouldn't name classes "~" both standard library , other libraries do, , need work them.

added: looking @ sschaef's answer tried

 $tilde.foo 

and works. not sure if that's intended or implementation detail of how names translated jvm-identifiers. , whether work in other flavors of scala (e.g. scala.js)?

i'll leave open bit see maybe chimes in more extensive answer.

the problem seems exist in 2.11:

welcome scala 2.11.8 (openjdk 64-bit server vm, java 1.8.0_102). type in expressions evaluation. or try :help. scala> object ~ { def foo = 0 } defined object $tilde  scala> ~.foo <console>:1: error: illegal start of simple expression ~.foo  ^ 

in 2.12 works fine:

welcome scala 2.12.0 (openjdk 64-bit server vm, java 1.8.0_102). type in expressions evaluation. or try :help. > object ~ { def foo = 0 } defined object $tilde > ~.foo res0: int = 0 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -