• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java 1.5 StringBuffer/StringBuilder

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm wondering why you just don't write:

listChanges.read(reader, null);
 
Tom Johnson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is listChanges a JTextArea?
 
Tom Johnson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No listChanges() is another method, it is irrelevant really for the compilation error im wondering about.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Yes, my master! Here is the tiny ad you asked for:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic