static-methods

Unit-testing a class that calls a static method

时光总嘲笑我的痴心妄想 提交于 2020-01-03 13:04:07
问题 I am trying to unit-test a class 'A' which calls a static method of a class 'B'. Class 'B' essentially has a google guava cache which retrieves a value(Object) from the cache given a key, or loads the object into the cache (in case of a cache-miss) using a service adapter. The service-adapter class in turn has other autowired dependencies to retrieve the object. These are the classes for illustration purposes: Class A public class A { public Object getCachedObject(String key) { return B

AsyncTask inside a Static method - Good Coding Practice?

吃可爱长大的小学妹 提交于 2020-01-03 08:33:10
问题 I currently have a helper class to perform rudimentary AsyncTasks such as the following. I call the function from an activity as and when needed. The code seems to work fine and I haven't encountered any problems. But, I was wondering if this is a good coding practice or if there were any ramifications that I am unaware of. Any feedback would be gladly accepted and appreciated. public class OtherUtils { public static void updatePromptsOption(final boolean showPrompt, final Context context) {

AsyncTask inside a Static method - Good Coding Practice?

廉价感情. 提交于 2020-01-03 08:33:09
问题 I currently have a helper class to perform rudimentary AsyncTasks such as the following. I call the function from an activity as and when needed. The code seems to work fine and I haven't encountered any problems. But, I was wondering if this is a good coding practice or if there were any ramifications that I am unaware of. Any feedback would be gladly accepted and appreciated. public class OtherUtils { public static void updatePromptsOption(final boolean showPrompt, final Context context) {

Find the class name of the calling function in php

与世无争的帅哥 提交于 2020-01-03 03:40:30
问题 Lets say I have: class Zebra{ public static function action(){ print 'I was called from the '.get_class().' class'; // How do I get water here? } } class Water{ public static function drink(){ Zebra::action(); } } Water::drink(); How do I get "water" from the zebra class? (This is for php 5.3) 回答1: One not so good solution is : use __METHOD__ or __FUNCTION__ or __CLASS__ . and pass it as parameter to function being called. http://codepad.org/AVG0Taq7 <?php class Zebra{ public static function

Swift - Type has no member

試著忘記壹切 提交于 2020-01-03 03:08:06
问题 I have a basic class named APIGroup that exists for the sole purpose of subclassing (it is not [yet] used for anything but certain static properties that are accessed by the subclasses). It looks somewhat like this: public class APIGroup { public static let someProperty : String = "I am a property!" } And I have a subclass, Track , which defines a type method search as follows: public class Track : APIGroup { public static func search(name: String) -> Void { print("Track search initiated.

how to call non static method from static method in android

假如想象 提交于 2020-01-02 07:26:45
问题 I am facing a big problem in calling non static method from static method. This is my code Class SMS { public static void First_function() { SMS sms = new SMS(); sms.Second_function(); } public void Second_function() { Toast.makeText(getApplicationContext(),"Hello",1).show(); // This i anable to display and cause crash CallingCustomBaseAdapters(); //this was the adapter class and i anable to call this also } I am able to call Second_function but unable to get Toast and CallCustomBaseAdapter()

Can static methods in javascript call non static

爱⌒轻易说出口 提交于 2020-01-02 04:15:09
问题 I am curious as I get a "undefined is not a function" error. Consider the following class: var FlareError = require('../flare_error.js'); class Currency { constructor() { this._currencyStore = []; } static store(currency) { for (var key in currency) { if (currency.hasOwnProperty(key) && currency[key] !== "") { if (Object.keys(JSON.parse(currency[key])).length > 0) { var currencyObject = JSON.parse(currency[key]); this.currencyValidator(currencyObject); currencyObject["current_amount"] = 0;

Static method and extension method with same name

倾然丶 夕夏残阳落幕 提交于 2020-01-02 03:37:04
问题 I created extension method: public static class XDecimal { public static decimal Floor( this decimal value, int precision) { decimal step = (decimal)Math.Pow(10, precision); return decimal.Floor(step * value) / step; } } Now I try to use it: (10.1234m).Floor(2) But compiler says Member 'decimal.Floor(decimal)' cannot be accessed with an instance reference; qualify it with a type name instead . I understand there is static decimal.Floor(decimal) method. But it has different signature. Why

How can I call member variables of a class within a static method?

笑着哭i 提交于 2020-01-02 01:55:47
问题 I am using some method to autoload helper files with functions. The only problem I am having now, is how to call the variables in that class. Because I am not instantiating it as an object, $this won't work. But what will? class some_helperclass { var $some_variable = '007'; public static function some_func() { //return 'all ok'; if (self::some_variable !== FALSE) { return self::ip_adres; } } I can call the function from anywhere now with the help of spl_autoload_register() . some_helperclass

Static method vs module function in python

风格不统一 提交于 2020-01-02 01:46:16
问题 So I have a class in a module that has some static methods. A couple of these static methods just do crc checks and stuff, and they're not really useful outside of the class (I would just make them private static methods in java or C++). I'm wondering if I should instead make them global class functions (outside of the class). Is there any benefit for doing it either way? The class is being imported by from module import class so I'm not worried about having those modules pulled in as well.