static-methods

How compatible are static class methods and regular routine pointers?

心不动则不痛 提交于 2019-12-12 09:53:35
问题 It seems to me that static class methods and regular routine pointers are compatible from a practical viewpoint but the compiler doesn't know this. Example: type TFunc = function(i: Integer): string; TMyClass = class public class function StaticMethod(i: Integer): string; static; end; class function TMyClass.StaticMethod(i: Integer): string; begin Result := '>' + IntToStr(i) + '<'; end; function GlobalFunc(i: Integer): string; begin Result := '{' + IntToStr(i) + '}'; end; procedure CallIt

Are Java arrays in a static method thread safe?

痞子三分冷 提交于 2019-12-12 08:33:46
问题 public static int rank(int key, int[] a) { int lo = 0; int hi = a.length - 1; while (lo <= hi) { // Key is in a[lo..hi] or not present. int mid = lo + (hi - lo) / 2; if (key < a[mid]) hi = mid - 1; else if (key > a[mid]) lo = mid + 1; else return mid; } return -1; } The above static method does binary search. Is it thread safe? I know that local variables are thread safe but "a" here is an array, so that means it's an object in Java, right? Is that a problem? The array is just being read, not

Advantage of using a static member function instead of an equivalent non-static member function?

女生的网名这么多〃 提交于 2019-12-12 08:05:48
问题 I was wondering whether there's any advantages to using a static member function when there is a non-static equivalent. Will it result in faster execution (because of not having to care about all of the member variables), or maybe less use of memory (because of not being included in all instances)? Basically, the function I'm looking at is an utility function to rotate an integer array representing pixel colours an arbitrary number of degrees around an arbitrary centre point. It is placed in

Why does my ASP.Net static function's “context” crossover between user sessions?

时光毁灭记忆、已成空白 提交于 2019-12-12 07:14:17
问题 I think I need some help understanding how static objects persist in an ASP.Net application. I have this scenario: someFile.cs in a class library: public delegate void CustomFunction(); public static class A { public static CustomFunction Func = null; } someOtherFile.cs in a class library: public class Q { public Q() { if (A.Func != null) { A.Func(); } } } Some ASP.Net page: Page_Init { A.Func = MyFunc; } public void MyFunc() { System.IO.File.AppendAllText( "mydebug.txt", DateTime.Now

new object is created or not?

北慕城南 提交于 2019-12-12 05:00:20
问题 I am reading Effective Java by Joshua Bloch. It confuses me in the item 1, where it states A second advantage of static factory method is that, unlike constructors, they are not required to create a new object each time time they're invoked. Isn't the static factory method meant to create a new object each time it is invoked? //constructor Orange(){ } //static factory method static Orange staticFactoryMethod(){ return new Orange; } Won't calling either the constructor or the

PHP Class constructor not running when called from static function in another class

别说谁变了你拦得住时间么 提交于 2019-12-11 19:24:03
问题 I am currently stamped and i can't see where I have done it wrong. I have a static function request() below: private static function request(){ if($_SERVER['REQUEST_METHOD']=='GET'){ $data = RunData::get('cmd'); } which calls a static function get() which in turn calls a private function clean() which uses variables set in the class constructor loading an Injected class Sanitize class RunData { public static $sanitize; public function __construct( Sanitize $sanitize ){ self::$sanitize =

Cocos2d with ARC: what is the best implementation of singleton pattern for GameScene when having multiple levels?

孤者浪人 提交于 2019-12-11 17:33:07
问题 EDIT: I am using ARC In my code (based on the ShootEmUp example in this book, which I highly reccomend, source code in chapter 8 available here) I often use the trick of accessing the GameScene via: +(GameScene*) sharedGameScene; which returns a reference to the static instance of GameScene and is used by all children of GameScene (e.g. ShipEntity, InputLayer.. etc..) to dialog with GameScene (EDIT: aka singleton instance of GameScene ). To create multiple levels I thought of implementing a

Shared class field in Visual Basic

余生颓废 提交于 2019-12-11 16:41:36
问题 I have a class, MyClass , declared as public, with a Shared method test() : Public Class MyClass Public Shared Function test() Return "sdfg" End Function ' snip other non-shared methods End Class This Class is located in the App_Code directory of the website, and appears to be visible, as I can instantiate an instance of the Class from any of the sites scripts. My issue relates specifically to accessing the Shared method test() . Trying to get this working, I have the following code in Page

PHP Static Properties, Inheritance, and the self keyword

自作多情 提交于 2019-12-11 15:34:33
问题 This doesn't make sense to me: class A { public static $value = "a"; public static function get_value(){ return self::$value; } } echo A::$value; // a, this makes sense echo A::get_value(); // a, this makes sense class B extends A { public static $value = "b"; } echo B::$value; // b, this makes sense echo B::get_value(); // a? :( Why doesn't the self pointer work as expected, similar to this ? Is there another keyword that could be used to accomplish this? If I add the static function to

Why can't I call a Static method from another class which contains a Toast?

故事扮演 提交于 2019-12-11 15:04:11
问题 Before posting this I did my research, but I am struggling to understand exactly what the issue is. So here is my method in class 1: public static void scan() { for( int j=0; j< objarray.size();j++) { locationB.setLatitude(objarray.get(j).getlat()); locationB.setLongitude(objarray.get(j).getlon()); float distance = locationA.distanceTo(locationB); if((distance < 600)&&(distance > 0.0) ) { Toast.makeText(getApplicationContext(),"You can go to" +objarray.get(j).gettitle(),Toast.LENGTH_SHORT)