call

toString() method within System.out.println() a double call?

泪湿孤枕 提交于 2019-11-30 12:14:48
A professor of mine once said that the following code should never be done: System.out.println(object.toString()); He said (and I believe cited "Effective Java") it causes a double call. Since the print statement calls the toString method of an object, it would be less efficient to have the toString method called twice. The preferred method would be to just use: System.out.println(object); Obviously this way looks better in code and would save time. I will always do it like this no matter what, but my question is "Is this actually more EFFICIENT?". In looking through the PrintStream

iOS: showing an alert when getting a call?

▼魔方 西西 提交于 2019-11-30 10:35:23
I would like a local notification to be fired when a call is received (and to show an alert) - is this possible? Can a call event get an app to launch or a notification to be fired? How is skype fired? With push notifications? Thanks If your application is running while a call is in place check out the CoreTelephony Framework . The CTCall class provides information about the call state. I have not used this myself but you may find it useful. extern NSString const *CTCallStateDialing; extern NSString const *CTCallStateIncoming; extern NSString const *CTCallStateConnected; extern NSString const

Speed of [].forEach.call(…?

血红的双手。 提交于 2019-11-30 09:51:31
I'm a big fan of using the forEach method on nodeLists like this: var nodes = document.querySelectorAll(".foo"); [].forEach.call(nodes, function (item) { //do stuff with item }); I was wondering though, does doing it that way take longer than the regular way? e.g. for(var i=0;i<nodes.length;i++){ //do stuff with nodes[i]; } Here's a nice performance comparison . According to it Array.forEach is slower than a native for loop. I know it's an old post but using the forEach method can be done by stealing the Array prototype as well. NodeList.prototype.forEach = Array.prototype.forEach; It depends

Batch file how to call another batch file at a specified label or call and immediately goto a certain label?

核能气质少年 提交于 2019-11-30 08:44:52
I am trying to figure out how file1.bat can call file2.bat at a specified label. I figured I can do it like this: File1.bat :config @echo off :setvars set labelmarker=labelmarker call file2.bat pause > nul :EOF File2.bat if %labelmarker%==labelmarker goto label4 :label1 echo it won't work... goto EOF :label2 echo it must work! goto EOF :label3 echo it didn't work... goto EOF :label4 echo it works! goto EOF :EOF This works. but I want to call a bat AND the Label from file1.bat. is it possible with a control character or ascii code or anything? like i tried call file2.bat | goto label4 - doesn't

How to use call_command with dumpdata command to save json to file

北城以北 提交于 2019-11-30 08:35:31
I am trying to use the call_command method to call the dumpdata command . Manually, I use it as follows to save the data to a file. python manage.py dumpdata appname_one appname_two > /path/to/save/file.json and it saves the json file. Now, I am in a situation where I need to call this command using the call_command method. I am able to print out the json from the command using the following: from django.core.management import call_command call_command('dumpdata', 'appname_one', 'appname_two') Is there a way I can save the given data to a file like we do it from the command line? had to

Calling private function within the same class python

♀尐吖头ヾ 提交于 2019-11-30 07:56:50
How can i call a private function from some other function within the same class? class Foo: def __bar(arg): #do something def baz(self, arg): #want to call __bar Right now, when i do this: __bar(val) from baz(), i get this: NameError: global name '_Foo__createCodeBehind' is not defined Can someone tell me what the reason of the error is? Also, how can i call a private function from another private function? There is no implicit this-> in Python like you have in C/C++ etc. You have to call it on self . class Foo: def __bar(self, arg): #do something def baz(self, arg): self.__bar(arg) These

Call javascript function which name is in variable [duplicate]

自作多情 提交于 2019-11-30 07:09:37
问题 This question already has answers here : How to execute a JavaScript function when I have its name as a string (32 answers) Closed 3 years ago . The problem is next: Assume that we have a select. Onchange event we need to call some function, but name of this function kept in variable. How to call this function ? 回答1: window[name]() You can call functions by name reference by selecting them as a property of window and executing them 回答2: have you tried variableName(); ? We often pass around

What's the meaning to chain call and apply together?

怎甘沉沦 提交于 2019-11-30 06:59:53
问题 I come across this code in jsGarden, and I cannot figure the meaning to chain call and apply together. Both will execute the function with a given context object, why it could be chained? function Foo() {} Foo.prototype.method = function(a, b, c) { console.log(this, a, b, c); }; // Create an unbound version of "method" // It takes the parameters: this, arg1, arg2...argN Foo.method = function() { // Result: Foo.prototype.method.call(this, arg1, arg2... argN) Function.call.apply(Foo.prototype

Why does `typeof this` return “object”?

大城市里の小女人 提交于 2019-11-30 05:58:02
问题 var f = function(o){ return this+":"+o+"::"+(typeof this)+":"+(typeof o) }; f.call( "2", "2" ); // "2:2::object:string" var f = function(o){ return this+":"+(typeof this)+":"+(typeof o); }; var x = [1,/foo/,"bar",function(){},true,[],{}]; for (var i=0;i<x.length;++i) console.log(f.call(x[i],x[i])); // "1:object:number" // "/foo/:object:object" // "bar:object:string" // "function () {\n}:function:function" // "true:object:boolean" // ":object:object" // "[object Object]:object:object" I see

Function calls vs. local variables

China☆狼群 提交于 2019-11-30 03:25:07
问题 I often see functions where other functions are called multiple times instead of storing the result of the function once. i.e (1) : void ExampleFunction() { if (TestFunction() > x || TestFunction() < y || TestFunction() == z) { a = TestFunction(); return; } b = TestFunction(); } Instead I would write it that way, (2) : void ExampleFunction() { int test = TestFunction(); if (test > x || test < y || test == z) { a = test; return; } b = test; } I think version 2 is much better to read and better