- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Why does Predef have "type String = java.lang.String", etc.?
Wed, 2009-03-25, 04:59
... instead of just using the fact that String can be used without qualification since the parser does an implicit "java.lang._" import? Is there a specific advantage to declaring the types vs. relying on the implicit imports? Or, is it possibly true that java.lang._ and scala._ aren't actually imported automatically, contrary to what I've read, so these definitions really are necessary?
Thanks in advance.
dean
--
Dean Wampler
twitter: @deanwampler, @chicagoscala
Chicago-Area Scala Enthusiasts (CASE):
- http://groups.google.com/group/chicagoscala
- http://www.meetup.com/chicagoscala/ (Meetings)
http://www.objectmentor.com
http://www.polyglotprogramming.com
http://www.aspectprogramming.com
http://aquarium.rubyforge.org
http://www.contract4j.org
Thanks in advance.
dean
--
Dean Wampler
twitter: @deanwampler, @chicagoscala
Chicago-Area Scala Enthusiasts (CASE):
- http://groups.google.com/group/chicagoscala
- http://www.meetup.com/chicagoscala/ (Meetings)
http://www.objectmentor.com
http://www.polyglotprogramming.com
http://www.aspectprogramming.com
http://aquarium.rubyforge.org
http://www.contract4j.org
Wed, 2009-03-25, 12:17
#2
Re: Why does Predef have "type String = java.lang.String", etc
It's to have a platform independent String, and the like. The standard
library for MSIL has a different type alias for String. Once the MSIL
backend is back on track (and we have someone actively working on
this), these aliases will have a more substantial motivation.
iulian
On Wed, Mar 25, 2009 at 6:07 AM, Eric Torreborre wrote:
>
> Hi Dean,
>
> I tried to do some experiment in the Scala console:
>
> import Predef.{String => Renamed}
> val s: String = "hello"
> val s2: Renamed = "hello"
> val s3 = new java.lang.String("hello")
> val p: Process = null
>
> And I get:
>
> import Predef.{String=>Renamed}
> s: String = hello
> s2: String = hello
> s3: java.lang.String = hello
> p: java.lang.Process = null
>
> So it seems that java.lang._ is imported automatically and even if you
> renamed the "String" type alias for java.lang.String, you still can access
> it.
>
> Eric.
> --
> View this message in context: http://www.nabble.com/-scala--Why-does-Predef-have-%22type-String-%3D-ja...
> Sent from the Scala mailing list archive at Nabble.com.
>
>
Hi Dean,
I tried to do some experiment in the Scala console:
import Predef.{String => Renamed}
val s: String = "hello"
val s2: Renamed = "hello"
val s3 = new java.lang.String("hello")
val p: Process = null
And I get:
import Predef.{String=>Renamed}
s: String = hello
s2: String = hello
s3: java.lang.String = hello
p: java.lang.Process = null
So it seems that java.lang._ is imported automatically and even if you
renamed the "String" type alias for java.lang.String, you still can access
it.
Eric.