methods

Casting problem in C# generic method

I'm having some trouble with a generic method I'm writing. It has the following signature; public static ThingCollection<T> GetThings<T>(...) where T : Thing There are several classes; ThingA, ThingB and ThingC that inherit from Thing; and I want to be able to have code something like this in the method. var things = new ThingCollec...

PHP: Callback on Entry/Exit of Class Methods?

Is there a way I can set up callbacks on (or automataically log) method parameters, entries, and exits without making explicit calls within each method? I basically want to log this information to my logger class (which is static) without having to do it manually for each method. Right now I have to call Logger::logEntry() and Logger::l...

Changing item in foreach thru method.

Let's start with the following snippet: Foreach(Record item in RecordList){ .. item = UpdateRecord(item, 5); .. } The UpdateRecode function changes some field of item and returns the altered object. In this case the compiler throws an exception saying that the item can not be updated in a foreach iteration. Now the UpdateRecor...

How to register a JavaScript callback in a Java Applet?

I'm developing an invisible Java Applet, that will be controlled entirely from JavaScript. I can call the applet's Java methods easily, and I can call JavaScript methods from within the applet by using netscape.javascript.JSObject.getWindow(this).call(). But in order to register a JavaScript callback in the applet, I guess I would need...

Java: `static` Methods

When I call a static method like: Something.action(); Since a instance isn't created how long will the Class of the static method be held in memory? If I call the same method will the Class be reloaded for each call since no instance exists? And are only individual static methods loaded when called or are all the methods and static ...

How to make a method to return random string in the format A1A 1A1?

I need a method to return a random string in the format: Letter Number Letter Number Letter Number (C#) ...

What Cases Require Synchronized Method Access in Java?

In what cases is it necessary to synchronize access to instance members? I understand that access to static members of a class always needs to be synchronized- because they are shared across all object instances of the class. My question is when would I be incorrect if I do not synchronize instance members? for example if my class is...

Only one return statement per method, even in this scenario?

Hi, I like the idea of having only 1 return statement per method. What do you do in this situation though? public static string ChopText(string Text) { if(String.IsNullOrEmpty(Text) { // return here ?????// } } The only alternative I can think of is setting a flag, and then checking for the flag. Problem is, I don't...

#inject and slowness

I've often heard Ruby's inject method criticized as being "slow." As I rather like the function, and see equivalents in other languages, I'm curious if it's merely Ruby's implementation of the method that's slow, or if it is inherently a slow way to do things (e.g. should be avoided for non-small collections)? ...

Pointer Pointer Methods C++

Hi, I have two questions: 1) How can I make an array which points to objects of integers? int* myName[5]; // is this correct? 2) If I want to return a pointer to an array, which points to objects (like (1)) how can I do this in a method? ie) I want to impliment the method: int **getStuff() { // what goes here? return *(myName); // ...

How can I do <form method="get"> in ASP.Net for a search form?

I have a search form in an app I'm currently developing, and I would like for it to be the equivalent of method="GET". Thus, when clicking the search button, the user goes to search.aspx?q=the+query+he+entered The reason I want this is simply bookmarkeable URLs, plus it feels cleaner to do it this way. I obviously don't want all the vie...

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

Background: I have a module which declares a number of instance methods module UsefulThings def get_file; ... def delete_file; ... def format_text(x); ... end And I want to call some of these methods from within a class. How you normally do this in ruby is like this: class UsefulWorker include UsefulThings def do_work ...

How can I disable HTTP Methods for Tomcat 5.5.27

Please let me know how can I disable HTTP MEthods like OPTIONS, PUT, DELETE for the web server Apache Coyote HTTP 1.1 Connector (Tomcat 5.5.27) ...

Is there a sweet, efficient way to call the same method twice with two different arguments?

Say for example I have the following string: var testString = "Hello, world"; And I want to call the following methods: var newString = testString.Replace("Hello", "").Replace("world", ""); Is there some code construct that simplifies this, so that I only have to specify the Replace method once, and can specify a bunch of parameters ...

Problem with return statement

I have problem with return statment >.< I want to store all magazine names into ArrayList<String> ListNameMagazine = new ArrayList<String>(); I have a DB; in the DB there is a table name_magazine and the data in name_magazine is Magazine1 Magazine2 Magazine3 Magazine4 This my main: ShowData Show = new ShowDa...

Why can't I call a public method in another class?

I've got these two classes interacting and I'm trying to call four different classes from class one for use in class two. The methods are public and they do return values but for some reason there is not a connection being made. The error I get when I try is: "An object reference is required for the nonstatic field, method, or property ...

How to run any method knowing only her fully qualified name

Hello, I've got a name of a method: "Garden.Plugins.Code.Beta.Business.CalculateRest" How to run it? I think about this fancy reflection based solution like RunMethod(string MethodName) ...

Is there a free tool to profile the execution time of Java methods?

Hello everybody, I need to know the usage by other applications, in time of execution, of java methods of an api created in my project, does someone know any free tool to know this? Thank you very much. ...

when to pass a parameter and when to use an instance variable

How do you guys decide between keeping track of something locally and then just passing it in to every method you call on it, or declaring an instance variable and using it in the methods? I tend to prefer instance variables kept in a list at the end of the Class. But as my programs become more and more complicated, this list gets longe...

What does the function set use to check if two objects are different?

Simple code: >>> set([2,2,1,2,2,2,3,3,5,1]) set([1, 2, 3, 5]) Ok, in the resulting sets there are no duplicates. What if the object in the list are not int but are some defined by me? What method does it check to understand if they are different? I implemented __eq__ and __cmp__ with some objects but set doesn't seems to use them :\ ...