This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes iOS and the fly likes how can i access no static data member in static method is there any solution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Mobile » iOS
Bookmark "how can i access no static data member in static method is there any solution" Watch "how can i access no static data member in static method is there any solution" New topic
Author

how can i access no static data member in static method is there any solution

Rizwan Lateef
Greenhorn

Joined: Aug 11, 2010
Posts: 7
how can i access no static data member in static method is there any solution, please tell me if any
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Would you please provide us a context here?
Are you talking about Java or Objective-C?
Rizwan Lateef
Greenhorn

Joined: Aug 11, 2010
Posts: 7
i m talking about objective c i think only way is by passing a parameter to that method

like if numberOfSides is nonstatic instance variable then we can pass it like

+ (NSString)getPolyName:(int)sides
Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 460
I believe that passing it (or the object it exists in) as a parameter is the only way to do so. An instance variable exists in an object, and there might be multiple objects of the same class, the static method will never know what to use, hence it's not allowed in the language, and it will not compile if you try to access an instance variable (or invoke an instance method) from a static method. (this applies to Java as well)


Visit my blog: http://jnassef.blogspot.com/
 
wood burning stoves
 
subject: how can i access no static data member in static method is there any solution