File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Java 1.5 StringBuffer/StringBuilder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java 1.5 StringBuffer/StringBuilder" Watch "Java 1.5 StringBuffer/StringBuilder" New topic
Author

Java 1.5 StringBuffer/StringBuilder

Tom Johnson
Ranch Hand

Joined: May 11, 2005
Posts: 142
Hi,
I have recently started using JDK1.5. I used to have code like the following :


This works fine in JDK1.4. However, when this is recompiled with 1.5.0_06, i get a compile time error at line **
"Type mismatch: cannot convert from AbstractStringBuilder to StringBuffer"

This is unexpected as the append method returns a StringBuffer object, not AbstractStringBuilder object.
Also, if you pass in a char ('c'), i get a compiler error "Cannot convert from Appendable to StringBuffer", even though again the append(), method returns a StringBuffer object.

Has anyone seen this before or can anyone explain why the method is returning a different object to that which its signature defined.

Cheers

/Tom


<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">Use Code Tags!!</a>
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Are you using an IDE? I tried compiling your code at the command line with 1.5.0_02 and didn't get a compile-time error.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I'm wondering why you just don't write:

listChanges.read(reader, null);


There is no emoticon for what I am feeling!
Tom Johnson
Ranch Hand

Joined: May 11, 2005
Posts: 142
Hi,
I am using the XDE IDE. Sorry I shouldnt have included the listChanges() bit, im just interested in the line **.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Is listChanges a JTextArea?
Tom Johnson
Ranch Hand

Joined: May 11, 2005
Posts: 142
No listChanges() is another method, it is irrelevant really for the compilation error im wondering about.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by Tom Johnson:
No listChanges() is another method, it is irrelevant really for the compilation error im wondering about.


listChanges sure looks like an object in your code:

Anyway, I would rewrite that as:

Although if you are trying to read into a text component, the JTextComponent read() method is the way to go.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java 1.5 StringBuffer/StringBuilder
 
Similar Threads
Guess the answer
AbstractStringBuilder is not visible
null
cannot able to reterive value comes as null
Sending an Array to a Servlet