aspose file tools*
The moose likes Beginning Java and the fly likes 'void' type not allowed here Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " Watch " New topic
Author

'void' type not allowed here

Arun C. Giridharan
Ranch Hand

Joined: Jul 11, 2010
Posts: 96


Dog.java:21: 'void' type not allowed here
System.out.println(mydogs[x].name+mydogs[x++].bark());


what does this mean 'void' type not allowed here ???
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Can't print a void return value. Either return a string, or do all the printing in bark().

Personally, having a method that prints " says Ruff!", and depending on the calling method to put something in front of it that makes sense, is the start of a bad API. Options would include just returning "ruff" and doing the additional work in the calling method, or doing the name + barking sound in the bark() method, but there are other options as well.
Arun C. Giridharan
Ranch Hand

Joined: Jul 11, 2010
Posts: 96
Thank you .... i forgot about return type (String)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 'void' type not allowed here