• Post Reply Bookmark Topic Watch Topic
  • New Topic

strange!!!!

 
sriram gupta
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i tried to compile followign code
class poi
{
public static void main(String[] args)
{StringBuffer sb1= new StringBuffer("HELLO");
char[] b={'a', 'b'};
System.out.println(sb1.setCharAt(3,b[1]));
}
}
in comopilation it is giving following error..

bpoi.java:6: Incompatible type for method. Can't convert void to char[].
can anybody tell me what is wrong...
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Helo!
Although this seems not be relating threads nor synchronization the answer lies in the api documentation - see methdos System.out.println and StringBuffer.setCharAt!
------------------
Antti Barck
It Solutions Consultant -- NSD Oy
Sun Certified Programmer for the Java™ 2 Platform
 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

SetCharAt returns a void & you are getting a compile error at your print statement.
Look at the following modified code :
class poi
{
public static void main(String[] args)
{
StringBuffer sb1= new StringBuffer("HELLO");
char[] b={'a', 'b'};
sb1.setCharAt(3,b[1]);
System.out.println("new string :"+sb1);
}
}
Originally posted by sriram gupta:
hi all,
i tried to compile followign code
class poi
{
public static void main(String[] args)
{StringBuffer sb1= new StringBuffer("HELLO");
char[] b={'a', 'b'};
System.out.println(sb1.setCharAt(3,b[1]));
}
}
in comopilation it is giving following error..

bpoi.java:6: Incompatible type for method. Can't convert void to char[].
can anybody tell me what is wrong...

 
Marcela Blei
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this thread to Java (beginner)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!