super

Do you put a super() call a the beginning of your constructors?

风格不统一 提交于 2019-12-08 17:38:05
问题 This is a question about coding style and recommended practices: As explained in the answers to the question unnecessary to put super() in constructor?, if you write a constructor for a class that is supposed to use the default (no-arg) constructor from the superclass, you may call super() at the beginning of your constructor: public MyClass(int parm){ super(); // leaving this out makes no difference // do stuff... } but you can also omit the call; the compiler will in both cases act as if

How super is implemented in Java?

自古美人都是妖i 提交于 2019-12-08 16:45:39
问题 Where the "super" is actually defined? [When we're using super.someMethod()]. Is it defined as a field in java.lang.Object class or java.lang.Class class? When we're calling from a subclass, super contains the reference to it's superclass.In the same manner the super in superclass itself has reference to it's superclass [In this way upto java.lang.Object]. So, how java injects the superclass references to the "super" field which enables us to call superclass methods ? Is there any under the

'super' object has no attribute '__eq__'

泪湿孤枕 提交于 2019-12-08 15:31:58
问题 When I try to override the magic method __eq__ , and use super to access the base method found in object , I get an error. There's no way this is a bug, but it sure feels like one: class A(object): def __eq__(self, other): return super(A, self).__eq__(other) A() == 0 # raises AttributeError: 'super' object has no attribute '__eq__' This is unintuitive because object.__eq__ exists, but for class A(object): pass it doesn't. If I'm not mistaken __eq__ resorts to an is check, so that may be the

The constructor ArrayAdapter<String> is undefined - super() marked

烂漫一生 提交于 2019-12-08 14:21:43
问题 I am a little helpless at the moment. I have following code public class ListViewAdapter<String> extends ArrayAdapter<String> { private final Context context; private final int textViewResourceId; private final int[] itemResourceIds; private final ArrayList<String> list; public ListViewAdapter(Context context, int textViewResourceId, int[] itemResourceIds, ArrayList<String> list) { super(context, textViewResourceId, itemResourceIds, list); this.context = context; this.textViewResourceId =

How to replace javascript method of super class for testing?

我的未来我决定 提交于 2019-12-08 13:58:19
问题 I want to test a method 'foo' that calls its super method 'foo': foo(){ super.foo(); //do some extra stuff } If it would reference another method from the same class, e.g. foo(){ this.baa(); //do some extra stuff } ... i could simply replace the baa method for testing, e.g element.baa = () => { console.log('This is a mock of baa')}; element.foo(); expect(effectsOfFoo).toBe(Ok). However, how to replace the super method 'foo'? Maybe something like element.constructor.getSuperClass().foo = () =>

How & Why to use SUPER in code?

坚强是说给别人听的谎言 提交于 2019-12-07 22:43:06
问题 I work with some advanced JavaScript people and they have used the SUPER keyword in their code. I admit, I don't have a good grasp of how and why one can and would use this. Can someone direct me or show me how to become well versed in its usage and reasoning thereof? Here are some examples: openup: function( $super ) { $super(); this.shop.enable_access(); } addLeft: function( data ) { var cell = Element('td'); if ( data.item_data ) { var item = new SRIL(data.item_data); item.attach(cell);

how does metaclass work with the MRO list when super() is called?

家住魔仙堡 提交于 2019-12-07 18:34:06
问题 I'm really confused by the following code sample: class Meta_1(type): def __call__(cls, *a, **kw): # line 1 print("entering Meta_1.__call__()") print(cls) # line 4 print(cls.mro()) # line 5 print(super(Meta_1, cls).__self__) # line 6 rv = super(Meta_1, cls).__call__(*a, **kw) # line 7 print("exiting Meta_1.__call__()") return rv class Car(object, metaclass=Meta_1): def __new__(cls, *a, **kw): print("Car.__new__()") rv = super(Car, cls).__new__(cls, *a, **kw) return rv def __init__(self, *a, *

Java set super instance of instance

你说的曾经没有我的故事 提交于 2019-12-07 12:10:50
问题 I might just be unable to google for the right words, but I can't find an answer to the following question. Is it possible to explicitly set the superclass of a new class instance. E.g. I have a SuperClazz instance and want to create a new instance of Clazz which extends SuperClazz . Can I just do something like this (the code is just what I want to do, it doesn't compile and is not correct): class Clazz extends SuperClazz{ Clazz(SuperClazz superInstance){ this.super = superInstance; } } 回答1:

How did Android implement the checks for SuperNotCalledException?

∥☆過路亽.° 提交于 2019-12-07 12:03:46
问题 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. 回答1: 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 (

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

眉间皱痕 提交于 2019-12-07 08:39:00
问题 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? 回答1: 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.