Link to home
Start Free TrialLog in
Avatar of acl6804
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().setInituwrtdt(new 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.



Avatar of pat5star
pat5star

I'm assuming program A is a class called DateUtil. If so, you can call it like this:

piObj.getContmstr().setInituwrtdt(DateUtil.getToday());

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
Avatar of acl6804

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.

ASKER CERTIFIED SOLUTION
Avatar of pat5star
pat5star

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of acl6804

ASKER

oh.. no wonder.. pat5star, can tell me what happend?

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