Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8400121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:28:57+00:00 2026-06-09T21:28:57+00:00

Maybe I am just crazy, or maybe I forgot the way things should work.

  • 0

Maybe I am just crazy, or maybe I forgot the way things should work. But I was chasing down a bug (while learning some Groovy) and found that the following assertion fails. I guess I thought that when using a string literal, a new instance of String would be created for it. Am I wrong?

String one = 'one'
String two = 'one'

// I thought this should fail, but it doesn't
assert one.is(two) == false

one = new String("one")
two = new String("one")

// This works as expected
assert one.is(two) == false

By using the dump() method, I can see that they are indeed the same instance of String. Any help or guidance would be appreciated.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:28:59+00:00Added an answer on June 9, 2026 at 9:28 pm

    When you use String literals, Java allows them to be interned, so you get the same instance..

    The section 2.3 in the VM spec mentions this.

    String literals and, more generally, strings that are the values of constant expressions are “interned” so as to share unique instances, using the method String.intern.

    Groovy also follows this rule

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe it is just a simple mistake but this thing is driving me crazy.
I know, I am crazy, considering I am literally just learning HTML. But I
Ok, so maybe I'm just going crazy, but did Facebook remove the option to
This may be way out in left field, crazy, but I just need to
May be its a simple question but it's really driving me crazy. I just
Maybe I just haven't figured out the InfoPath paradigm yet, but any links, or
Doesn't seem to work for me, maybe I just doing it wrong
I'm interested in texture streaming in DirectX but google seems unhelpful. Maybe I just
Maybe I am just over thinking this and need to write some more prototype
So, maybe I just suck at searching, but I'm having real trouble finding a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.