methods

Can Java store methods in arrays?

Well I wrote some code and all I was doing was for loops, but changing which method I called. I tried using a for loop so it'd be a bit neater (and out of curiosity to see if it could be done), but it doesn't compile when I do it this way, because it doesn't recognize an item in an array as a method, I think. This is what I have: String...

C++ member function applied to object

hi I want to call member function by passing it as template parameter, without using boost is possible. Here is an example off what I tried to do, class object { void method(); } { object object_instance; ... apply<object:: method>(); ... template<class F> void apply() { F(object_instance); } // want to call object_instance.F() } t...

PHP: run class method when another class method is run?

PHP: run function when a specific class method is run what I want is to run some additional functions when a class method is run without altering the already existing class. how? ...

How do I pass an event handler as a method parameter?

How can I pass the event handler TextBlock_MouseDown_Test1 or TextBlock_MouseDown_Test2 to SmartGrid so that the TextBlocks which it creates will execute this event handler when they are clicked? The code below gets the error: The best overloaded method match for 'TestDel234.SmartGrid.SmartGrid(TestDel234.Window1, System.Collec...

Class exists in an external file.

How do I check an external file for a class? I am trying to setup a install feature for my modules, so I am trying to get it to load a list of directories and then check if the module file has a method called install. So only the modules with this method will be shown in the list. Here is my code so far: $output .= '<div id="module-di...

C# Delegate Instantiation vs. Just Passing the Method Reference

I have a simple question: what's the advantage of instantiating a C# delegate as opposed to just passing the function reference? What I mean is: Why do: Thread t = new Thread(new ThreadStart(SomeObject.SomeMethod)); When you can do: Thread t = new Thread(SomeObject.SomeMethod); Both will compile and work in my experience...am I m...

How to calculate bridge method target...

Generics bring in a lot of goodness to java but they also mean trouble because of the introduction of bridge methods which mean its not easy to locate a method given a name and target because erasure and bridge methods mean clients actually use the bridge rather than the target. Return types from methods have been omitted because they a...

Reflection: How to Invoke Method with parameters

Hello, I am trying to invoke a method via reflection with parameters and I get "object does not match target type". If I invoke a method without parameters it works fine. Based on the following code if I call the method Test("TestNoParameters") it works fine. However if I call Test("Run") I got an exception. Is something wrong with my c...

Event handler cannot access Object method in JavaScript

How can I access util.log() method from a static html event handler? In other words, when I click the checkbox, I like to call util.log method. onclick="util.log(\'hey\')" <-- how to rewrite the event function here? I know all the answers are correct down here but is it possible to access local methods while insert the html into inne...

How to assign a value from a C# static method to a label

Hi, I have the following static function in c# public static string Greet(string name) { string greeting = "welcome "; // is it possible to pass this value to a label outside this static method? string concat = string.Concat(greeting, name); //error Label1.text = concat; //I want ...

java code to create dynamic methods at runtime

I have a dynamic list of variables for which I need to create getter and setter on the fly i.e. during runtime. ...

Using type object as returning type - bad practice ?

I have a method private object SetGrid(IGrid grid) { grid.PagerHelper.SetPage(1, 10); grid.SortHelper.SetSort(SortOperator.Ascending); grid.PagerHelper.RecordsPerPage = 10; return grid; } which returns an object of type object. Then I cast the object back to the previous type. var pr...

moving a function out of my method in django

Hay i have a method in my view which uploads an image, the image is then saved to a db object. I want to remove this from my view and either put it in my model or a seperate file. filename_bits = request.FILES['image'].name.split(".") filename_bits.reverse() extension = filename_bits[0] # create filename and open a destination filename...

Why not abstract fields?

Why can't Java classes have abstract fields like they can have abstract methods? For example: I have two classes that extend the same abstract base class. These two classes each have a method that is identical except for a String constant, which happens to be an error message, within them. If fields could be abstract, I could make thi...

Rails defining methods

I would like to define a method where the first argument is required and the rest are optional. Only first argument must be at first pace. I try to do this: my_method(:id, :tags, :user) my_method(:id, :user, :tags) def(id, *args) ... id... ... args[:tags]... ... args[:user]... end Thank you! ...

Get all models having implemented a certain method

I have many models created with the standard rails model generator. Some of the models have then got a method called foo(). Is there a simple way to figure out all the class names of the generated models having the foo() method implemented ? I mean programmaticaly, from a rails controller, not from the console grepping the sourcecode....

Partition method

Hi, I am trying to understand exactly what this method does, it say its suppose to "Keep swapping the outer-most wrongly-positioned pairs". I put this into a program and tried different array but the result make no sense to me, what exactly does this do partition(A, p) A: array of size n, p: integer s.t. 0 <= p < n 1. swap(A[0],A[p...

What are 3 possible situations in which static methods might be included in classes?

I got this question for homework, and all I can think of is to return a subclass of an abstract superclass. Thanks! ...

How do I log every method that's called in a Ruby program?

I've inherited a large pile of Ruby code that's, frankly, close to impossible to understand for a mortal like myself. It's actually Rspec unit test code, but the structure is "highly unusual" to put it nicely. What I'd like to be able to do is run the code, and have the following information logged somewhere: every method that gets i...

Break method chaining in php

Hi I am using method chaining for my class structure. So my problem is that , how could i break my chain when error occurred in some function. Below is my code: <?php class demo { public __construct() { $this->a='a'; $this->b='b'; $this->error = false; } p...