super

(iphone) what does [super touchesBegan/Moved/Ended] do?

◇◆丶佛笑我妖孽 提交于 2019-12-06 01:54:13
问题 Most overloaded methods require [super theMethod] call. (For example, [super viewDidLoad]; , [super viewWillAppear]; and [super dealloc]; ) I didn't think twice whether I need [super touchesBegan:withEvent:] call or not, but it seems to play a role somehow. When do I need it and when don't I need it? I'm trying to programmatically cancel touch events when I need to, and it seems to be related to the question I asked. 回答1: While it all depends on the expected behaviors of the object, let's

Confused about “super” keyword in this Java example

↘锁芯ラ 提交于 2019-12-06 01:47:32
问题 In this example on java website's tutorial page. Two interfaces define the same default method startEngine() . A class FlyingCar implements both interfaces and must override startEngine() because of the obvious conflict. public interface OperateCar { // ... default public int startEngine(EncryptedKey key) { // Implementation } } public interface FlyCar { // ... default public int startEngine(EncryptedKey key) { // Implementation } } public class FlyingCar implements OperateCar, FlyCar { // ..

How did Android implement the checks for SuperNotCalledException?

白昼怎懂夜的黑 提交于 2019-12-05 19:27:30
In the Activity class, Android provides runtime enforcement that super() must be called for overridden lifecycle callback methods. If you forget do do so, it throws SuperNotCalledException. Exactly how was this implemented specifically on Android? Please point me to the actual source implementation if possible. It looks like they clear a flag in the super methods and check that it was set : final void performStart() { mCalled = false; mInstrumentation.callActivityOnStart(this); if (!mCalled) { throw new SuperNotCalledException( "Activity " + mComponent.toShortString() + " did not call through

why and how to use Python's super(type1, type2)?

会有一股神秘感。 提交于 2019-12-05 15:43:13
super has 2 args, super(type, obj_of_type-or-subclass_of_type) I understand how and why to use super with the 2nd arg being obj_of_type. But I don't understand the matter for the 2nd arg being subclass. Anyone can show why and how? outis You pass an object if you want to invoke an instance method. You pass a class if you want to invoke a class method. The classic example for using super() for class methods is with factory methods, where you want all the superclass factory methods to be called. class Base(object): @classmethod def make(cls, *args, **kwargs): print("Base.make(%s, %s) start" %

[python]: confused by super() [duplicate]

空扰寡人 提交于 2019-12-05 14:54:32
This question already has answers here : Closed 8 years ago . Possible Duplicate: Understanding Python super() Class B subclasses class A , so in B's __init__ we should call A's __init__ like this: class B(A): def __init__(self): A.__init__(self) But with super() , I saw something like this: class B(A): def __init__(self): super(B, self).__init__() #or super().__init__() My questions are: Why not super(B, self).__init__(self) ? Just because the return proxy object is a bound one? If I omit the second argument in super and the return proxy object is an unbound one, then should I write super(B).

Scala overloaded constructors and super

会有一股神秘感。 提交于 2019-12-05 13:32:41
I can't understand how to develop Scala code similar to the following on Java: public abstract class A { protected A() { ... } protected A(int a) { ... } } public abstract class B { protected B() { super(); } protected B(int a) { super(a); } } public class C extends B { public C() { super(3); } } while it's clear how to develop C class, I can't get how to receive B. Help, please. P.S. I'm trying to create my own BaseWebPage derived from wicket WebPage which is a common practice for Java Do you mean something like: abstract class A protected (val slot: Int) { protected def this() = this(0) }

Why is Python 3.x's super() magic?

痴心易碎 提交于 2019-12-05 12:25:07
In Python 3.x, super() can be called without arguments: class A(object): def x(self): print("Hey now") class B(A): def x(self): super().x() >>> B().x() Hey now In order to make this work, some compile-time magic is performed, one consequence of which is that the following code (which rebinds super to super_ ) fails: super_ = super class A(object): def x(self): print("No flipping") class B(A): def x(self): super_().x() >>> B().x() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in x RuntimeError: super(): __class__ cell not found Why is super()

When extending a trait within a trait, what does 'super' refer to?

痞子三分冷 提交于 2019-12-05 11:39:36
问题 I want to to extend a trait within a trait, like this: trait NodeTypes { trait Node { def allNodesHaveThis: Int } } trait ScrumptiousTypes extends NodeTypes { trait Node extends super.Node { def scrumptiousness: Int } } trait YummyTypes extends NodeTypes { trait Node extends super.Node { def yumminess: Int } } object Graph extends NodeTypes with ScrumptiousTypes with YummyTypes { case class Node() extends super.Node { override def allNodesHaveThis = 1 override def scrumptiousness = 2 // error

Java - using the 'super' keyword

╄→尐↘猪︶ㄣ 提交于 2019-12-05 11:11:22
Simple question. I made a class called Tester1 which extends another called Tester2. Tester2 contains a public string called 'ABC'. Here is Tester1: public class Tester1 extends Tester2 { public Tester1() { ABC = "Hello"; } } If I instead change line 5 to super.ABC = "Hello"; am I still doing the exact same thing? Yes. There's only one ABC variable within your object. But please don't make fields public in the first place. Fields should pretty much always be private. If you declared a variable ABC within Tester1 as well, then there'd be a difference - the field in Tester1 would hide the field

Does any magic happen when I call `super(some_cls)`?

∥☆過路亽.° 提交于 2019-12-05 05:14:36
While investigating this question , I came across this strange behavior of single-argument super : Calling super(some_class).__init__() works inside of a method of some_class (or a subclass thereof), but throws an exception when called anywhere else. Code sample: class A(): def __init__(self): super(A).__init__() # doesn't throw exception a = A() super(A).__init__() # throws exception The exception being thrown is Traceback (most recent call last): File "untitled.py", line 8, in <module> super(A).__init__() # throws exception RuntimeError: super(): no arguments I don't understand why the