134得票3回答
何时应该使用 @classmethod 和 def method(self)?

在集成一个我之前没有使用过的Django应用程序时,我发现有两种不同的方式来定义类内函数。作者似乎故意地使用它们进行区分。第一种是我自己经常使用的方式:class Dummy(object): def some_function(self, *args, **kwargs): ...

117得票5回答
使用-performSelector:和直接调用方法有何区别?

我在学习Objective-C,想知道下面两个语句的区别:[object performSelector:@selector(doSomething)]; [object doSomething];

53得票4回答
从字符串调用方法

如果我有一个Python类,并且想根据变量调用其中的函数,我该怎么做?我想以下代码可以实现: class CallMe: # Class def App(): # Method one ... def Foo(): # Method two ......

24得票5回答
重载是编译时多态性。真的吗?

我知道重写和重载之间的语法差异。我也知道重写是运行时多态,而重载是编译时多态。但我的问题是:“重载真的是编译时多态吗?方法调用是否真的在编译时解决?” 为了澄清我的观点,让我们考虑一个示例类。public class Greeter { public void greetMe() { ...

13得票4回答
Java方法分派中使用null参数

为什么直接传递null参数和传递赋有值null的Object参数会产生不同的结果呢?Object testVal = null; test.foo(testVal); // dispatched to foo(Object) // test.foo(null); // compil...

10得票1回答
运行时,Swift 如何知道使用哪个实现?

protocol A { func f() } struct S1 : A { func f() { print("S1") } } struct S2 : A { func f() { print("S2") } }...

7得票2回答
send和getattr的PHP等效函数是什么?

如果 Ruby 被邀请参加派对并带了以下物品: foobarobject.send('foomethod') ...Python也受邀参加同一个聚会,并带来了: getattr(foobarobject, 'foomethod')() PHP有什么值得一提的东西? 奖励问题:如...