Join us in building a kind, collaborative learning community via our updatedCode of Conduct.

Questions tagged [methods]

A method is a block of code that performs a task and is associated with a class or an object. It is related to the non-object-oriented concepts of functions and procedures.

5510
votes
78answers
1.6m views

Is Java “pass-by-reference” or “pass-by-value”?

I always thought Java was pass-by-reference.However, I've seen a couple of blog posts (for example, this blog) that claim that it isn't.I don't think I understand the distinction they're making. ...
2683
votes
25answers
562k views

What is the difference between @staticmethod and @classmethod in Python?

What is the difference between a function decorated with @staticmethod and one decorated with @classmethod?
1508
votes
16answers
935k views

Are static class variables possible?

Is it possible to have static class variables or methods in python? What syntax is required to do this?
1451
votes
32answers
555k views

What's the difference between a method and a function?

Can someone provide a simple explanation of methods vs. functions in OOP context?
1315
votes
19answers
875k views

Does Java support default parameter values?

I came across some Java code that had the following structure:public MyParameterizedFunction(String param1, int param2){this(param1, param2, false);}public MyParameterizedFunction(String ...
523
votes
10answers
479k views

Pass Method as Parameter using C#

I have several methods all with the same signature (parameters and return values) but different names and the internals of the methods are different. I want to pass the name of the method to run to ...
508
votes
17answers
170k views

Adding a Method to an Existing Object Instance

I've read that it is possible to add a method to an existing object (i.e., not in the class definition) in Python. I understand that it's not always good to do so. But how might one do this?
447
votes
10answers
112k views

Why are exclamation marks used in Ruby methods?

In Ruby some methods have a question mark (?) that ask a question like include? that ask if the object in question is included, this then returns a true/false.But why do some methods have ...
427
votes
18answers
299k views

What is the difference between class and instance methods?

What's the difference between a class method and an instance method?Are instance methods the accessors (getters and setters) while class methods are pretty much everything else?
390
votes
19answers
309k views

Getting the name of the currently executing method

Is there a way to get the name of the currently executing method in Java?
359
votes
1answer
19k views

List view getListItemXmlAttributes method fails with child publication items

I have created a JS class to populate SG/Folder list view data, when items are modified. (As per Jaime's approach)Everything works great when I operate on items in the publication they're created in....
326
votes
4answers
190k views

Why do some functions have underscores “__” before and after the function name?

This seems to occur a lot, and was wondering if this was a requirement in the Python language, or merely a matter of convention?Also, could someone name and explain which functions tend to have the ...
304
votes
10answers
75k views

How to find where a method is defined at runtime?

We recently had a problem where, after a series of commits had occurred, a backend process failed to run. Now, we were good little boys and girls and ran rake test after every check-in but, due to ...
270
votes
16answers
430k views

When is the finalize() method called in Java?

I need to know when the finalize() method is called in the JVM. I created a test class which writes into a file when the finalize() method is called by overriding it. It is not executed. Can anybody ...
235
votes
20answers
186k views

Cannot refer to a non-final variable inside an inner class defined in a different method

Edited:I need to change the values of several variables as they run several times thorugh a timer. I need to keep updating the values with every iteration through the timer. I cannot set the values ...
218
votes
6answers
60k views

Difference between method and function in Scala

I read Scala Functions (part of Another tour of Scala). In that post he stated:Methods and functions are not the same thingBut he didn't explain anything about it. What was he trying to say?
200
votes
5answers
135k views

Why does Mockito not mock static methods?

I read a few threads here about static methods, and I think I understand the problems misuse/excessive use of static methods can cause. But I didn't really get to the bottom of why it is hard to mock ...
195
votes
6answers
171k views

How to display all methods of an object?

I want to know how to list all methods available for an object like for example:alert(show_all_methods(Math));This should print: abs, acos, asin, atan, atan2, ceil, cos, exp, floor, log, max, ...
175
votes
5answers
23k views

Final arguments in interface methods - what's the point?

In Java, it is perfectly legal to define final arguments in interface methods and do not obey that in the implementing class, e.g.:public interface Foo {public void foo(int bar, final int baz);...
174
votes
4answers
93k views

Method Syntax in Objective C

Can someone explain this method declaration syntax for me? In this function, the number of rows of a UIPickerView (slot machine UI on the iPhone) is being returned. From my understanding, the ...
174
votes
21answers
75k views

Should private helper methods be static if they can be static

Let's say I have a class designed to be instantiated. I have several private "helper" methods inside the class that do not require access to any of the class members, and operate solely on their ...
173
votes
8answers
464k views

How to call multiple JavaScript functions in onclick event?

Is there any way to use the onclick html attribute to call more than one JavaScript function?
164
votes
7answers
292k views

Reflection: How to Invoke Method with parameters

I am trying to invoke a method via reflection with parameters and I get:object does not match target typeIf I invoke a method without parameters, it works fine. Based on the following code if I ...
156
votes
21answers
31k views

When is a Java method name too long? [closed]

In the last weeks I've seen some guys using really long names for a Method or Class (50 characters), this is usually under the premise that it improves readability, my opinion is that a long name like ...
156
votes
6answers
233k views

How do I pass multiple parameters in Objective-C?

I have read several of the post about Objective-C method syntax but I guess I don't understand multiple names for a method.I'm trying to create a method called getBusStops with NSString and ...
155
votes
8answers
205k views

What's a “static method” in C#?

What does it mean when you add the static keyword to a method?public static void doSomething(){//Well, do something!}Can you add the static keyword to class? What would it mean then?
153
votes
9answers
103k views

Can I invoke an instance method on a Ruby module without including it?

Background:I have a module which declares a number of instance methodsmodule UsefulThingsdef get_file; ...def delete_file; ...def format_text(x); ...endAnd I want to call some of ...
144
votes
13answers
94k views

Why can't I declare static methods in an interface?

The topic says the most of it - what is the reason for the fact that static methods can't be declared in an interface?public interface ITest {public static String test();}The code above ...
140
votes
15answers
62k views

Is it wrong to use Deprecated methods or classes in Java?

I am using eclipse to develop a web application. Just today I have updated my struts version by changing the JAR file. I am getting warnings at some places that methods are deprecated, but the code is ...
139
votes
8answers
93k views

Java synchronized static methods: lock on object or class

The Java Tutorials say: "it is not possible for two invocations of synchronized methods on the same object to interleave." What does this mean for a static method? Since a static method has no ...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,