methods

Best way to pass values to a function when there are many to send?

岁酱吖の 提交于 2019-12-12 15:11:18
问题 What is the best way to define a method signature when you have to pass many values to a function and some of these may be optional. And in future, May be I have to pass more variables or subtract some passed values given to function. For example: (phone and address are optional) function addInfo( $name, $dob, $phone='', $address='' ) { // Store data } addInfo( 'username', '01-01-2000', '1111111' ); // address is not given OR function addInfo( $info ) { // Store data } $info = array( 'name'=>

Cannot Assign to 'Money' Because It Is a 'Method Group'

僤鯓⒐⒋嵵緔 提交于 2019-12-12 15:09:01
问题 I'm doing a project for class, and I have to call the Money function from my Player class. However, I do not know how to change Money into something else that is not a Method Group . I don't know much programming, so my range of solutions is rather small. Also, the instructor said I cannot make any changes to the Main class, only to the Player class. Here's the code for the Main class: p1.Money += 400; And here's the 'Money' function from my Player class: public int Money () { return money; }

Replacing if statement with for loop (Java)

廉价感情. 提交于 2019-12-12 14:37:10
问题 I was working on a project and one of the comments that I received was that my if statement was too long. I agree with this but I'm still confused how to replace it with a for loop that was suggested. It has been driving me crazy. The project was to analyse the consonants in a sentence and report back if they are in it. Here is my code that I used. The project has been since marked so this is more of a "where is my mistake/ where can this be improved question". if ((userInput.contains("b"))||

Is there a way to declare a method “friendly” in Java?

∥☆過路亽.° 提交于 2019-12-12 14:28:53
问题 I know that attributes can be set public , friendly or private to specify its visibility. Is there a way I can declare a friendly method? I want it to be accessible only from objects of classes of the same package. Thanks you, a beginner here :(. 回答1: By not entering a visiblity modifier Java uses the package private scope Check out the following article Edit: As mentioned in the comments, there is no way to mark a method as "friendly". But for your needs, package-private will suffice. 回答2:

shouldChangeCharactersInRange call twice

不打扰是莪最后的温柔 提交于 2019-12-12 13:55:23
问题 Sometimes, shouldChangeCharactersInRange is called twice when I hit only one character. As an exemple, i enter 'avion par c', the procedure is called and add me a second 'c' result is 'avion par cc' - How can I avoid that ? This happened only since I migrate the application to iOS 7, xCode 5. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { wordSearching = YES; if ([string isEqualToString:@"\n"]) { [self

Java: returning two ints from a method call

删除回忆录丶 提交于 2019-12-12 13:15:18
问题 I do this a lot in my code that works with lots of 2 dimensional coordinates: int[] getSize() { int[] res = {gridRows, gridColumns}; return res; } I know that I could define a tiny class and get type safety but I haven't because it annoys me to have such a trivial class in it's own little trivial .java file that I have to incorporate in my code. Do you think this is ugly, bad, or evil? Or do you do it too? 回答1: If there's a concept in your project that you want to encapsulate, for instance,

How can I pass a method name to another method and call it via a delegate variable?

北城余情 提交于 2019-12-12 13:02:39
问题 I have a method that contains a delegate variable that points at another class. I want to call a method in that class via this delegate, but pass the name of the method as a string to the method containing the delegate. How can this be done? Using reflection? Func<T> ? Edit: I understand now that reflection may not be the best solution. This is what I have: private static void MethodContainingDelegate(string methodNameInOtherClassAsString) { _listOfSub.ForEach(delegate(Callback callback) { /

npm ERR! 405 Method Not Allowed: express@latest

自闭症网瘾萝莉.ら 提交于 2019-12-12 12:12:16
问题 Of the several 405 related Questions posted here, none apply to my issue. Here is the command I issued from Windows 7 on my Desktop PC: npm install express Here is the Error message: npm ERR! code E405 npm ERR! 405 Method Not Allowed: express@latest npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\mr9832\AppData\Roaming\npm-cache\_logs\2018-02-21T20_36_09_581Z-debug.log Here is the verbose Error Log mentioned above C:\Users\mr9832\AppData\Roaming\npm-cache_logs\2018-02

How can I call a function in another CFC file from within a query of a function in one cfc file?

主宰稳场 提交于 2019-12-12 11:34:22
问题 I have one cfc file (info.cfc) with multiple functions as shown below. <cfcomponent output="true" extends="DateFunctions"> <cffunction name="getStatuses" access="remote" returntype="any" output="true" returnformat="plain"> ... </cffunction> <cffunction name="viewDate" access="remote" returntype="any" output="true" returnformat="plain"> <cfquery name="records"> SELECT dbo.tickets.Incident, dbo.tickets.Start_Date, dbo.tickets.Days_Due FROM dbo.tickets </cfquery> </cffunction> </component> And

Should methods that implement pure virtual methods of an interface class be declared virtual as well?

这一生的挚爱 提交于 2019-12-12 10:37:09
问题 I read different opinions about this question. Let's say I have an interface class with a bunch of pure virtual methods. I implement those methods in a class that implements the interface and I do not expect to derive from the implementation. Is there a need for declaring the methods in the implementation as virtual as well? If yes, why? 回答1: No - every function method declared virtual in the base class will be virtual in all derived classes. But good coding practices are telling to declare