super

How to force derived class to call super method? (Like Android does)

 ̄綄美尐妖づ 提交于 2019-11-28 05:36:26
I was wondering, when creating new Activity classes and then overriding the onCreate() method, in eclipse I always get auto added: super.onCreate() . How does this happen? Is there a java keyword in the abstract or parent class that forces this? I don't know if it is illegal not to call the super class, but I remember in some methods that I got a exception thrown for not doing this. Is this also built-in into java? Can you use some keyword to do that? Or how is it done? Here's the source of Activity#onCreate() - it is almost all comments ( original - see line ~800 ): /** * Called when the

ES6 What does super() actually do in constructor function?

孤者浪人 提交于 2019-11-28 04:03:01
问题 ! Hola, amigos. I have this little class inheritance structure class Point { constructor(x, y) { this.x = x; this.y = y; } toString() { return '(' + this.x + ', ' + this.y + ')'; } } class ColorPoint extends Point { constructor(x, y, color) { super(x, y); this.color = color; } toString() { return super.toString() + ' in ' + this.color; } } let newObj = new ColorPoint(25, 8, 'green'); It compiles to this jsfiddle I get how it works in es6 in a silly way. But could somebody explain how does it

Locations of super() calls in Android Eclipse Plugin generated code reliable?

送分小仙女□ 提交于 2019-11-27 22:09:29
In many of Android methods, especially constructors and overridden methods, you should or even must call the parent class method using super() . When you use the Eclipse Source > Override/Implement Methods... you get code from a template with TODO tags like this: public MyCanvas(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); } I do not understand exacly what the superclass does in each case so I always insert my code at the exact

calling a super method from a static method

走远了吗. 提交于 2019-11-27 21:57:13
Is it possible to call a super static method from child static method? I mean, in a generic way, so far now I have the following: public class BaseController extends Controller { static void init() { //init stuff } } public class ChildController extends BaseController { static void init() { BaseController.loadState(); // more init stuff } } and it works, but I'd like to do it in a generic way, something like calling super.loadState(), which doesn't seem to work... sgokhales In Java, static methods cannot be overidden. The reason is neatly explained here So, it doesn't depend on the object that

How to call super method from grandchild class?

非 Y 不嫁゛ 提交于 2019-11-27 21:49:42
I am working with some code that has 3 levels of class inheritance. From the lowest level derived class, what is the syntax for calling a method 2 levels up the hierarchy, e.g. a super.super call? The "middle" class does not implement the method I need to call. Well, this is one way of doing it: class Grandparent(object): def my_method(self): print "Grandparent" class Parent(Grandparent): def my_method(self): print "Parent" class Child(Parent): def my_method(self): print "Hello Grandparent" Grandparent.my_method(self) Maybe not what you want, but it's the best python has unless I'm mistaken.

Getting the name of a sub-class from within a super-class

僤鯓⒐⒋嵵緔 提交于 2019-11-27 20:49:56
问题 Let's say I have a base class named Entity . In that class, I have a static method to retrieve the class name: class Entity { public static String getClass() { return Entity.class.getClass(); } } Now I have another class extend that. class User extends Entity { } I want to get the class name of User: System.out.println(User.getClass()); My goal is to see "com.packagename.User" output to the console, but instead I'm going to end up with "com.packagename.Entity" since the Entity class is being

Which of the 4 ways to call super() in Python 3 to use?

浪尽此生 提交于 2019-11-27 20:34:17
I wonder when to use what flavour of Python 3 super (). Help on class super in module builtins: class super(object) | super() -> same as super(__class__, <first argument>) | super(type) -> unbound super object | super(type, obj) -> bound super object; requires isinstance(obj, type) | super(type, type2) -> bound super object; requires issubclass(type2, type) Until now I've used super() only without arguments and it worked as expected (by a Java developer). Questions: What does "bound" mean in this context? What is the difference between bound and unbound super object? When to use super(type,

In Java super.getClass() prints “Child” not “Parent” - why is that?

早过忘川 提交于 2019-11-27 19:30:59
问题 In Java classes and objects, we use "this" keyword to reference to the current object within the class. In some sense, I believe "this" actually returns the object of itself. Example for this: class Lion { public void Test() { System.out.println(this); //prints itself (A Lion object) } } In the scenario of a superclass and subclass. I thought that "super" keyword would return the object of the superclass. However it seems that I got it wrong this time: Example: class Parent { public Parent(){

Using Super in an Objective C Category?

▼魔方 西西 提交于 2019-11-27 19:04:53
I'd like to override a method in an Objective C class that I don't have the source to. I've looked into it, and it appears that Categories should allow me to do this, but I'd like to use the result of the old method in my new method, using super to get the old methods result. Whenever I try this though, my method gets called, but "super" is nil... Any idea why? I'm doing iPhone development with the XCode 2.2 SDK. I'm definitely working with an instance of a class, and the method of the class is an instance method. @implementation SampleClass (filePathResolver) -(NSString*)

How do I force a polymorphic call to the super method?

给你一囗甜甜゛ 提交于 2019-11-27 17:45:36
问题 I have an init method that is used and overridden through out an extensive heirarchy. Each init call however extends on the work that the previous did. So naturally, I would: @Override public void init() { super.init(); } And naturally this would ensure that everything is called and instantiated. What I'm wondering is: Can I create a way to ensure that the super method was called? If all of the init's are not call, there is a break down in the obejct, so I want to throw an exception or an