0

i am learning scala as i have experience in java but i have following doubts in scala.

java

String str1 = "Hello"
String str2 = "Hello"

java allocate same memory for the string and have two reference as str1 and str2. when we compare str1==str2 we will get true as java would compare reference.

my question is how scala would allocate memory for same string as given above? what is the way to compare the value of String and its reference?

i am getting confuse while learning object comparison in scala?

can somebody explain me with examples for String memory allocation and comparison of String and objects?

adithyan .p
  • 121
  • 1
  • 3
  • 12
  • thanks for the link , as from the link eq is used to compare reference, if so can i compare class reference also or only String reference? – adithyan .p Nov 13 '17 at 09:05
  • 1
    What is a "class reference"? What is a "String reference"? Can you provide a *precise* specification of what it is that you want to happen, including any and all rules, exceptions from those rules, corner cases, special cases, boundary cases, and edge cases? Can you provide sample inputs and outputs demonstrating what you expect to happen, both in normal cases, and in all the exceptions, corner cases, special cases, boundary cases, and edge cases? – Jörg W Mittag Nov 13 '17 at 09:38
  • lets' say person p1 = new person; person p2 = new person; can i compare the object reference like p1 eq p2? and same in string var str1 = "hello"; var str2 = "jai" then compare reference like str1 eq str2? – adithyan .p Nov 13 '17 at 11:35

0 Answers0