This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

updating the date

 
Chris Lavery
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have been writing a class for a server of a message board to store the title of a topic, the date of the last post, the message ID, the author of the message and the no.of messages on a topic.
iv written this all fine but im now trying to write a method that should be called to update the date when a new posting occurs. any help is always much apreciated. My code is as follows:

public String getDate(){
return (Date);
}
public void setDate(String latestDate)
{

}
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do have a member variable in the class that holds the date, right? Is it called "Date" (that's what you're returning in the getDate method)?

First of all, rename it to "date" instead of "Date". It's not a good idea to name your variables with exactly the same names as classes (in this case, class java.util.Date).

In your set method, you simply assign the value of the parameter (latestDate) to the member variable.
 
Chris Lavery
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks jesper,
so would this do the job do you think:

public String getDate(){
return (date);
}

public void setDate(String latestDate)
{
latestDate = date;
}
 
Henry Wong
author
Marshal
Pie
Posts: 20836
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
Don't mean to offend you, but a "message board server" may be too ambitious. You might want to consider something easier.

Anyway, assignments are defined the other way around, the variable that you want to assign is on the left.



Henry
 
k Oyedeji
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try



If your get method returns a field which is of type date you will need to change the signature of getDate() as well as illustrated

HTH
 
Chris Lavery
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks everyone, it did the job perfect
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic