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.

5595
votes
77answers
1.7m 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. ...
2793
votes
24answers
587k views

What is the difference between @staticmethod and @classmethod?

What is the difference between a function decorated with @staticmethod and one decorated with @classmethod?
1480
votes
31answers
570k views

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

Can someone provide a simple explanation of methods vs. functions in OOP context?
1345
votes
19answers
907k 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 ...
645
votes
7answers
1.5m views

Is arr.__len__() the preferred way to get the length of an array in Python?

In Python, is the following the only way to get the number of elements?arr.__len__()If so, why the strange syntax?
534
votes
10answers
495k 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 ...
516
votes
17answers
176k 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?
455
votes
10answers
115k 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 ...
428
votes
18answers
301k 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?
395
votes
20answers
317k views

Getting the name of the currently executing method

Is there a way to get the name of the currently executing method in Java?
358
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....
338
votes
4answers
195k 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 ...
307
votes
10answers
76k 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 ...
279
votes
16answers
436k 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
187k 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 ...
221
votes
6answers
62k 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?
208
votes
5answers
140k views

Why doesn't Mockito 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 ...
206
votes
6answers
178k 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, ...
183
votes
9answers
481k 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?
180
votes
8answers
173k views

Why does Python code use len() function instead of a length method?

I know that python has a len() function that is used to determine the size of a string, but I was wondering why it's not a method of the string object.UpdateOk, I realized I was embarrassingly ...
179
votes
21answers
76k 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 ...
176
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 ...
167
votes
7answers
300k 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 ...
161
votes
6answers
236k 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 ...
158
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 ...
155
votes
9answers
106k 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 ...
155
votes
8answers
211k 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?
144
votes
13answers
95k 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 ...
143
votes
15answers
64k 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 ...

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