Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

understanding Equality

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in chapter 3 of OCA ithis program :

but i don't undrestand why not(x==z) return true given that trim() will delete the space in begin Consequently the two variable x and z will point on the same pool
 
Marshal
Posts: 69373
276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

emma roberts wrote:. . . the two variable x and z will point on the same pool

Why? String references only point to the same object if the two are compile‑time constants or interned. The trim() method doesn't produce a compile‑time constant or anything, and intern() isn't used there, so the two references won't point to the same object.
 
emma roberts
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you give me some documentation to understand more this notion
 
Campbell Ritchie
Marshal
Posts: 69373
276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java® Language Specification about constant expressions.
String#intern() method. It tells you which Strings are interned. It is only interned Strings that fulfil the implication s1.equals(s2) ⇒ s1 == s2
Old post of mine with two links in; I think you should read them both.
 
Don't touch me. And dont' touch this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic