Why 2 String Objects are created ?

Why is the line

String s2 = "bb"

is creating 2 objects ?

(I checked it using DevPartner Java Profiler, which gave me object count).

I am using JDK 1.5.0_10 !!

I thought String Literals are placed in Literal Pool and further compile time resolvable String objects are created at compile time only (in this case, s2 is compile time resolvable, right ?)

I have also not used the "new" operator (which forces new Object creation).

So why 2 objects. Any idea ?

[506 byte] By [kakarotha] at [2007-11-26 16:47:38]
# 1
> So why 2 objects. Any idea ?I doubt that that line creates two string instances.Kaj
kajbja at 2007-7-8 23:15:07 > top of Java-index,Java Essentials,New To Java...
# 2
It is.I told u, i am using DevPartner Java Profiler which marks a particular line and gives objects created and bytes used for each line. I am getting 2 objects per line and double the size i have mentioned.
kakarotha at 2007-7-8 23:15:08 > top of Java-index,Java Essentials,New To Java...
# 3
sorry, no mentioned size.
kakarotha at 2007-7-8 23:15:08 > top of Java-index,Java Essentials,New To Java...
# 4

> It is.

> I told u, i am using DevPartner Java Profiler which

> marks a particular line and gives objects created and

> bytes used for each line. I am getting 2 objects per

> line and double the size i have mentioned.

I really doubt your tool. See your other thread. Do you really think that the size of "a" is zero bytes?

kajbja at 2007-7-8 23:15:08 > top of Java-index,Java Essentials,New To Java...
# 5
You are right.Let me check out the tool first and then i will get back to you.Thanks.
kakarotha at 2007-7-8 23:15:08 > top of Java-index,Java Essentials,New To Java...