method-dispatch

When should I use @classmethod and when def method(self)?

孤者浪人 提交于 2019-11-26 15:13:58
问题 While integrating a Django app I have not used before, I found two different ways used to define functions in classes. The author seems to use them both very intentionally. The first one is one I myself use a lot: class Dummy(object): def some_function(self,*args,**kwargs): do something here self is the class instance The other one is one I do not use, mostly because I do not understand when to use it, and what for: class Dummy(object): @classmethod def some_function(cls,*args,**kwargs): do

Using -performSelector: vs. just calling the method

别说谁变了你拦得住时间么 提交于 2019-11-26 08:43:48
问题 I\'m still kind of new to Objective-C and I\'m wondering what is the difference between the following two statements? [object performSelector:@selector(doSomething)]; [object doSomething]; 回答1: Basically performSelector allows you to dynamically determine which selector to call a selector on the given object. In other words the selector need not be determined before runtime. Thus even though these are equivalent: [anObject aMethod]; [anObject performSelector:@selector(aMethod)]; The second

Java method dispatch with null argument

ε祈祈猫儿з 提交于 2019-11-26 06:50:08
问题 Why does it (apparently) make a difference whether I pass null as an argument directly, or pass an Object that I assigned the value null ? Object testVal = null; test.foo(testVal); // dispatched to foo(Object) // test.foo(null); // compilation problem -> \"The method foo(String) is ambiguous\" public void foo(String arg) { // More-specific System.out.println(\"foo(String)\"); } public void foo(Object arg) { // Generic System.out.println(\"foo(Object)\"); } In other words, why is the