Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.toString prints object id #3711

Closed
scabug opened this issue Jul 28, 2010 · 4 comments
Closed

Array.toString prints object id #3711

scabug opened this issue Jul 28, 2010 · 4 comments
Assignees
Labels

Comments

@scabug
Copy link

scabug commented Jul 28, 2010

C:\opt\scala-2.8.0.final\bin>scala.bat
Welcome to Scala version 2.8.0.final (Java HotSpot(TM) Client VM, Java 1.6.0_21).
Type in expressions to have them evaluated.
Type :help for more information.

scala> Array(1,2)
res0: Array[Int] = Array(1, 2)

scala> println(res0.toString())
[I@fa88fb

scala>
@scabug
Copy link
Author

scabug commented Jul 28, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3711?orig=1
Reporter: Eugene (euee)

@scabug
Copy link
Author

scabug commented Jul 28, 2010

@retronym said:
Array[Int] is precisely the same as int[] in Java. Scala can't doesn't attempt to change the result of Array[T]#toString.

The pretty output on the first line is a nicety of the REPL, but can only work in an expression evaluates to Array.

See:

http://stackoverflow.com/questions/2481149/why-does-array0-1-2-array0-1-2-not-return-the-expected-result
http://stackoverflow.com/questions/3328085/scala-printing-arrays
http://stackoverflow.com/questions/1973397/string-representation-of-objects-as-in-scala-repl/1973591SI-1973591
http://stackoverflow.com/questions/3213368/strange-behaviour-of-the-array-type

And probably more I missed.

@scabug
Copy link
Author

scabug commented Jul 28, 2010

Eugene (euee) said:
Thank you!
but is it a compatibility problem?

C:\opt\scala-2.7.7.final\bin>scala.bat
Welcome to Scala version 2.7.7.final (Java HotSpot(TM) Client VM, Java 1.6.0_21).
Type in expressions to have them evaluated.
Type :help for more information.

scala> Array(1,2)
res0: Array[Int] = Array(1, 2)

scala> println(res0.toString())
Array(1, 2)

scala>

@scabug
Copy link
Author

scabug commented Jul 28, 2010

@paulp said:
Replying to [comment:3 euee]:

Thank you!
but is it a compatibility problem?

Only if someone was depending on the output of toString. Rather unwise.

In any case, 2.7 is much worse from a consistency standpoint. Extending your example a little:

Welcome to Scala version 2.7.7.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20).
Type in expressions to have them evaluated.
Type :help for more information.

scala> Array(1,2)            
res0: Array[Int] = Array(1, 2)

scala> println(res0.toString())
Array(1, 2)

scala> println(res0)           
[I@36d98810

scala>  

@scabug scabug closed this as completed May 18, 2011
@scabug scabug added the repl label Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants