methods

PHP, distinguish between internal and external class method call

点点圈 提交于 2019-12-08 03:18:56
问题 Can't get my head around this, is there any way to check if a method was called internally? By this I mean a traceback to check if it was called by $this and not a pointer to the instance. Kind of like the concept of private function but only function is public? <?php class Foo { public function check () { /* if invoked by $this (internally) return true else return false */ } public function callCheck () { /* returns true because its called by $this */ return $this->check(); } } $bar = new

validator method not work in the JSF custom composite components

十年热恋 提交于 2019-12-08 03:02:27
JSF custom composite components input.xhtml <cc:interface> <cc:attribute name="validator"/> </cc:interface> <cc:implementation> <h:inputText validator="#{cc.attrs.validator}"/> </cc:implementation> *.xhtml <l:input value = ... validator="#{testValidator.validator}"/> java code @ManagedBean public class TestValidator { public void validator(FacesContext context, UIComponent component, Object value) throws ValidatorException { System.out.println("Call validator"); } } PropertyNotFoundException: validator="#{testValidator.validator}": The class 'TestValidator' does not have the property

Java add remove methods of sets

旧时模样 提交于 2019-12-08 02:52:10
问题 Why does the method add(<T> element) and remove(Object o) accept different arguments? For example in a Set<Short> you add short elements. Why does the method remove accepts Object ? If you can't add any other data type, why would you remove other data type? Thank you. 回答1: add(<T> element) : to ensure that just a T element is added. remove(Object o) : you can delete the T element even if it's a referenced by an Object reference. For instance : T t = new T(); Set<Short> set = new HashSet<Short

Why is http.Client{} prefixed with &?

ぐ巨炮叔叔 提交于 2019-12-08 02:29:23
问题 I am learning Go and I am reading Go's official documentation about net/http, and I write following code from doc for test: package main import ( "net/http" "fmt" ) func main() { client := &http.Client{} resp, _ := client.Get("http://example.com") fmt.Println(resp) } http.Client is a struct, but I do not know why there is a & pointer prefixed. I think creating a http.Client reference is not necessary. And why does the client variable have a Get method? I am reading the source code of net/http

How to figure out dynamically all methods with custom attribute

蹲街弑〆低调 提交于 2019-12-08 02:28:40
问题 I have a simple challenge. I dynamically need to figure out all methods with a specific attribute in C#. I'm going to load the assemblies dynamically from another application and need to find out the exact methods. The assemblies look like the followings: Base.dll: Class Base { [testmethod] public void method1() ... } Derived.dll: Class Derived:Base { [testmethod] public void method2() } Now in 3rd application I dynamically like to load the above mentioned dlls and find out testmethods. If I

Get object call hierarchy

戏子无情 提交于 2019-12-08 02:15:01
问题 Lets say I have 3 classes: class A { void do_A() { //Check object call hierarchy } } class B { void do_B() { A a; a.do_A(); } } class C { void do_C() { B b; b.do_A(); } } And then I call: C c; c.do_C(); How can i get the object call hierarchy from within A's do_A() ? I mean I want to get the references of object in a.do_A() (can be easily attained by this ), the reference of object b that called a.do_A() , and the reference of object c that called b.do_B() . I think this should be possible,

Objective C - “Duplicate declaration of method” compilation error

帅比萌擦擦* 提交于 2019-12-08 01:44:46
问题 I have this piece of code: - (id) getSearchSuggestions:(NSString*)q; - (NSOperationQueue*) getSearchSuggestions:(NSString*)q callback:(id<UserDelegate>)callback; - (id) getSearchSuggestions; - (NSOperationQueue*) getSearchSuggestions:(id<UserDelegate>)callback; And I Xcode keeps showing me an error on the last line: Duplicate declaration of method "getSearchSuggestions" Why? It seems to me that the signatures are all different. 回答1: This signature: - (id) getSearchSuggestions:(NSString*)q; Is

Anyway to simplify this rats nest of foreach loops?

為{幸葍}努か 提交于 2019-12-08 01:38:56
问题 This works but is uglier than hell, basically it's iterating through two separate portions of a sub array, seeing if there's a greatest common denominator besides 1 in the values of both sub arrays, and if there is, multiplying the base value by 1.5 Sorry for the sloppy code ahead of time. error_reporting(E_ALL); ini_set('display_errors', '1'); class CSVParser { public $output = NULL; public $digits = NULL; public function __construct($file) { if (!file_exists($file)) { throw new Exception("

Using Fractions in Python

那年仲夏 提交于 2019-12-08 01:31:24
I'm using classes here to input a fraction (when given the numerator and denominator), as well as add and multiply two fractions together. For some reason, the imported fractions module only works correctly for part of the program; the gcd method works, but the Fraction method (where when given two numbers, puts into fraction format) does not work, instead throwing a NameError (specifically, "global name 'Fractions' is not defined"). What am I doing wrong? I am relatively new to Python, and any suggestions on how to make this code tighter with more exceptions would be greatly appreciated. Here

Instance vs. static method. Calling it statically or dynamically

放肆的年华 提交于 2019-12-08 01:22:40
问题 In PHP there is instance methods and static methods (just these two types)? Then we can call either of these statically or non-statically (is the name "dynamically"?)? So we can: Call an instance method statically; Call an instance method non-statically; Call a static method statically; Call a static method non-statically (all four correct?) How would the code for these four look? Are there any good websites explaining this? I am currently reading the following url: http://php.net/manual/en