...and why has the package this misleading name (I assumed it had something to do with JavaME or mobile/smart phones)?
I found no references on the internet about scala.mobile.Code
or scala.mobile.Location
at all nor did I manage to do anything with those classes except getting ClassCastExcetion
s or NoSuchMethodError
s.
Actually there is not even a single test against scala.mobile
in the Scala's test tree which could help understanding that code.
The classes really smell like they were forgotten in the source tree a long time ago and got accidentally released since that.
Maybe I just missed something about them?
U开发者_C百科pdate:
scala.mobile
was removed in Scala 2.9.
I just checked the source code.
When Scala changed the name mangling of class files a few years ago and it seems people forgot to update these classes accordingly.
So my answer would be:
At least Location
has no purpose, because it is not possible to get anything sensible out of it (except exceptions) and Code
without Location
is severely limited. It works though if you pass the class literal to Code
directly:
import scala.mobile._
val c = new Code(classOf[scala.collection.mutable.StringBuilder])
c.apply[StringBuilder, String]("append")("Foo")
c.apply[String]("toString")() // returns "Foo"
c.apply[Int]("length")() // returns 3
Looks like yet-another implementation in the standard library of reflection-slightly-nicer.
The description of Location
pretty much explains what that is about:
The class
Location
provides a create method to instantiate objects from a network location by specifying the URL address of the jar/class file.
It might be used by remote actors. Maybe.
As for why it has this misleading name? Well, back in 2004 smart phones had really low penetration, so maybe the association wasn't all that strong.
精彩评论