Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

does this make sense

 
Chris Lavery
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my code for a server, in one of the classes i must store 5 details, one of them is the no. of messages on a topic. in order to increment this by one everytime a new message is posted i have the following code, it compiles fine but as i am only starting this project can anybody tell me if this looks to have any problems:

public int getNoMsgs(){
return (NoMsgs);
}

public void incNoMsgs(int inc)
{
inc = getNoMsgs();
inc++;
incNoMsgs(inc);
}
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your public void incNoMsgs(int inc) method is recursive (i.e. it calls itself). How is a call to this method ever going to end?
 
Henry Wong
author
Marshal
Pie
Posts: 20835
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not only is it recursive, it really doesn't make sense. The first operation immediately overwrites the amount to increment...

Henry
 
Chris Lavery
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys,
so what to i want to do to it??
 
Henry Wong
author
Marshal
Pie
Posts: 20835
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chris Lavery:
thanks guys,
so what to i want to do to it??


I don't think that giving you the answer is a good idea -- as you won't learn anything... but since it is Thanksgiving, and I am already running real late...



Happy Turkey Day...
Henry
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic