super

Java - Super.toString() method in base class?

自古美人都是妖i 提交于 2020-01-30 13:04:33
问题 My question is what is the reason to write Super.toString() in base class and what it returns and why ? this is my code : class Person { public String toString() { return super.toString() /*+ "->" + "Person" + name + "------"*/; } } what is supposed to be return ? and thanks i m beginner in java 回答1: Your class Person should extend parent class where you define method toString(), otherwise your parent class is class Object and the native method of this class is going to be used: public String

Behavior difference between super().__init__() and explicit superclass __init__() in Python

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-23 05:41:06
问题 I am getting an unexplained difference in behavior between using super().__init__() and explicitly calling a super class constructor in my code. class IPElement(object): def __init__(self, ip_type='IPv4'): self.ip_type = ip_type class IPAddressSimple(IPElement): def __init__(self, ip_name, ip_type='IPv4'): self.ip_name = ip_name super().__init__(self, ip_type=ip_type) Here, the line super().__init__(self, ip_type=ip_type) results in a type error: TypeError: __init__() got multiple values for

Calling the setter of a super class in a mixin

房东的猫 提交于 2020-01-17 05:14:28
问题 Suppose I have the following (not quite biologically correct) classes: class AnimalBaseClass: def __init__(self): self._limbs = None @property def limbs(self): return self._limbs @limbs.setter def limbs(self, value): self.paws = value self._limbs = value class BipedalMixIn: @property def limbs(self): return super().limbs @limbs.setter def limbs(self, value): self.bipedal = (value == 2) # does not work super().limbs = value Here super().limbs = value is not supported by python. If BipedalMixIn

Avoider Game Tutorial: Score not working

独自空忆成欢 提交于 2020-01-17 00:25:32
问题 I've been working on the tutorial for a neat avoider game over at this site: http://gamedev.michaeljameswilliams.com/2009/02/03/avoider-game-tutorial-5/ . I got as far as part 5, and up till then, I followed the code exactly (I stopped before running the final score at game over), and I event disabled auto-kernel and used device fonts, and embedded the text. Except when I run the game, no matter how many enemies show up, my score doesn't change from 0. Apparently, I keep getting the 1009

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

a 夏天 提交于 2020-01-13 11:29:07
问题 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

Get “super(): no arguments” error in one case but not a similar case

为君一笑 提交于 2020-01-12 14:26:26
问题 class Works(type): def __new__(cls, *args, **kwargs): print([cls,args]) # outputs [<class '__main__.Works'>, ()] return super().__new__(cls, args) class DoesNotWork(type): def __new__(*args, **kwargs): print([args[0],args[:0]]) # outputs [<class '__main__.doesNotWork'>, ()] return super().__new__(args[0], args[:0]) Works() # is fine DoesNotWork() # gets "RuntimeError: super(): no arguments" As far as I can see, in both cases super._new__ receives the class literal as first argument, and an

Accessing indirect super class variable that has been hidden in a third extended class

久未见 提交于 2020-01-11 12:05:14
问题 Suppose i have a code as below : class A { int a = 1; } class B extends A { int a = 2; } class C extends B { int a = 3; void print_it() { int a = 4; // Local variable "a" to the " print_it " method System.out.println(a); //Should be 4 System.out.println(this.a); //Should be 3 System.out.println(super.a); //Should be 2 System.out.println("HOW DO I PRINT \" a \" OF THE \" CLASS A \" "); //I need to print 1 } public static void main(String[] argue) { C obj = new C(); obj.print_it(); } } How can

Should Java classes call super() when they have no parent class? [duplicate]

天涯浪子 提交于 2020-01-04 05:53:08
问题 This question already has answers here : When do you need to explicitly call a superclass constructor? (3 answers) Closed 5 years ago . Is it necessary or good practice to call super() when you're class only has Object as a parent? i.e. public class Foo { public Foo() { super(); // Other stuff } } or public class Foo { public Foo() { // Other stuff } } 回答1: No. It's implicitly invoked, so theres no reason to call it. 来源: https://stackoverflow.com/questions/24308447/should-java-classes-call

Javascript - call super on parents parent?

☆樱花仙子☆ 提交于 2020-01-04 05:30:31
问题 I have defined this extension of current custom javascript view in Odoo: openerp.account_move_journal_test = function(instance){ var _t = instance.web._t, _lt = instance.web._lt; var QWeb = instance.web.qweb; instance.web.account.QuickAddListView.include({ init: function(){ this._super.apply(this, arguments); console.log("QuickAddListView modified init") }, }); }; Now for better representation I added console log in QuickAddListView and in ListView , which are parents that are called using

Unit testing overridden methods which call super()

为君一笑 提交于 2020-01-04 02:17:19
问题 I'm trying to figure out the best way of writing a unit test for an overridden method which calls super() as the last step. Basically, I want to massage parameters before they're used in the base class. Here's an example of a method: @Override public JobExecution run(Job job, JobParameters passedParams) throws JobExecutionAlreadyRunningException, JobRestartException { JobParameters launchParameters; if(passedParams.isEmpty()) { launchParameters = jobParameterSetter.getJobParameters(); } else