ram_os
asked on
static method
Hi,
I have a method which I am calling from another class. Eclipse is forcing me to change the method to static and I dont know why.
Any ideas?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Perhaps because you are calling it with the class-name? Can we look at the class that you're trying to call (I'm assuming you are calling it from another class). Also - is it an inner class by any chance? For the basics - a static method can be called by directly using the class-name and you don't need to create objects to call them.
ASKER
no I havent created an instance, so whenever I call a method on another class that I havent created an instance of, the method has to be static?
>> so whenever I call a method on another class that I havent created an instance of, the method has to be static?
Yes.
Yes.
>> so whenever I call a method on another class that I havent created an instance of, the method has to be static?
Yes.
Yes.
A class basically defines a template for an entity. You define data-members inside it which are like its attributes and then you define methods that perform operations on those attributes. So if you want to do it for a specific instance of a class, the methods will be instance-methods. If the class, on the other hand, defines something like a utility and need not necessarily have instances as there will no difference between them, then you can make its methods static.
ASKER
ok, could that affect existing calls on the method that werent static but now are?
But I wouldn't tend to make every method you want to use outside your class static.
What's the problem in creating an instance and call it on that?
What's the problem in creating an instance and call it on that?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm leaving for the day now.
ASKER
ok, thanks for that
:-)
So, my comment - posted at the same time as CEHJ's - is useless?
ASKER
Sorry zzynx, cehz was there first, i suppose i should have split the points further, i didnt take notice of the posted times.
>> i suppose i should have split the points further
It's never too late. ;°)
Would you like me to ask a reopen of this Q so you can reclose applying another split?
It's never too late. ;°)
Would you like me to ask a reopen of this Q so you can reclose applying another split?
ASKER
its up to yourself, would be only worth 50 points for you
>> its up to yourself
No, I ask it to you. Do you agree with a reopen?
>> would be only worth 50 points for you
Doesn't matter. For me, it's the principal that counts: a good comment that helped you deserves (some) points.
No, I ask it to you. Do you agree with a reopen?
>> would be only worth 50 points for you
Doesn't matter. For me, it's the principal that counts: a good comment that helped you deserves (some) points.
ASKER
Yep I agree
http://mindprod.com/jgloss/static.html