• Post Reply Bookmark Topic Watch Topic
  • New Topic

void type not allowed here  RSS feed

 
satya narayan reddy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.*;
public class VectorMethodsDemo
{
public static void main(String args[])
{
Vector v = new Vector();
System.out.println(""+v);
System.out.println(""+v.size());
System.out.println("" +v.setSize(9));//1
System.out.println("" +v.setElementAt("ramu",5));//2
}
}

Hi all,
Can anybody tell me why the above program with respect to comments 1 and 2 are showing :
void not allowed here as the compile time error

thanks,
satya
 
Steve Fahlbusch
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

Could it be:


-- from Vector javadoc --


setSize

public void setSize(int newSize)


--------------------------------------------------------------------------------

setElementAt

public void setElementAt(java.lang.Object obj, int index)


you are tying to print voids?
[ November 29, 2005: Message edited by: Steve Fahlbusch ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by satya narayan reddy:
import java.util.*;
public class VectorMethodsDemo
{
public static void main(String args[])
{
Vector v = new Vector();
System.out.println(""+v);
System.out.println(""+v.size());
System.out.println("" +v.setSize(9));//1
System.out.println("" +v.setElementAt("ramu",5));//2
}
}

Hi all,
Can anybody tell me why the above program with respect to comments 1 and 2 are showing :
void not allowed here as the compile time error

thanks,
satya


"" +v.setSize(9) calls the toString method of the object returned by v.setSize() in order to create a String, so if v.setSize() has a void return type (doesn't return an object) the compiler will complain.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you expect the following line to do -- what were you trying to do and to print?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!