acl6804
asked on
How to avoid this messsage (Static Issues)
This is my code:
program A:
========
...
...
public static synchronized Date getToday()
{
return new Date();
}
..
..
trying to access from here..
Program B:
=======
...
...
piObj.getContmstr().setIni tuwrtdt(ne w DateUtil().getToday());
...
...
And my "warning" message is this :
The static method getToday() from the type DateUtil should be accessed in a static way.
Question
=====
How can i resovel this issues?
ThankYou.
program A:
========
...
...
public static synchronized Date getToday()
{
return new Date();
}
..
..
trying to access from here..
Program B:
=======
...
...
piObj.getContmstr().setIni
...
...
And my "warning" message is this :
The static method getToday() from the type DateUtil should be accessed in a static way.
Question
=====
How can i resovel this issues?
ThankYou.
ASKER
but if i remove the "new" in the line, i will haev this problem.
"The method DateUtil() is undefined for the type PropInputServlet
** PropInputServlet is the name of my program B.
"The method DateUtil() is undefined for the type PropInputServlet
** PropInputServlet is the name of my program B.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
oh.. no wonder.. pat5star, can tell me what happend?
static means no need "new"??
static means no need "new"??
"static means no need "new"??"
Your right. Static methods or fields are like global variables or functions. You only use the "new" keyword when you are creating a new object.
-Pat
Your right. Static methods or fields are like global variables or functions. You only use the "new" keyword when you are creating a new object.
-Pat
piObj.getContmstr().setIni
You do not need to use the 'new' keyword when calling a static method. You just use the class name and the method you are calling.
Hope that helps,
-Pat