super

In Java type arguments, does <? extends E> mean strictly subtypes only? or would E also suffice?

血红的双手。 提交于 2019-12-05 03:43:12
In Java type arguments, does mean strictly subtypes only? or would E also suffice? Yes, super and extends gives inclusive lower and upper bounds respectively. Here's a quote from Angelika Langer's Generics FAQ : What is a bounded wildcard? A wildcard with an upper bound looks like ? extends Type and stands for the family of all types that are subtypes of Type , type Type being included . Type is called the upper bound . A wildcard with a lower bound looks like ? super Type and stands for the family of all types that are supertypes of Type , type Type being included . Type is called the lower

python3 - behaviour of super() on multi-inheritance

给你一囗甜甜゛ 提交于 2019-12-05 02:53:56
I know that super() and multi-inheritance have already been discussed here. But I did not find a solution, regarding my specific problem in python3. Let's assume we have: #! /usr/bin/env python3 class A(object): def __init__(self): super().__init__() def foo(self): print("The") class B(object): def __init__(self): super().__init__() def foo(self): print("world") class C(B): def __init__(self): super().__init__() def foo(self): super().foo() print("is") class D(A,C): def __init__(self): super().__init__() def foo(self): super().foo() print("nice") d = D() d.foo() This will get me: The nice On

Why is 'super' a keyword rather than a method in Ruby?

谁都会走 提交于 2019-12-05 02:10:11
In Ruby, super is a keyword rather than a method. Why was it designed this way? Ruby's design tends toward implementing as much as possible as methods; keywords are usually reserved for language features that have their own grammar rules. super , however, looks and acts like a method call. (I know it would be cumbersome to implement super in pure Ruby, since it would have to parse the method name out of caller , or use a trace_func . This alone wouldn't prevent it from being a method, because plenty of Kernel 's methods are not implemented in pure Ruby.) It behaves a little differently, in

Why doesn't OrderedDict use super?

半城伤御伤魂 提交于 2019-12-05 00:51:37
问题 We can create an OrderedCounter trivially by using multiple inheritance: >>> from collections import Counter, OrderedDict >>> class OrderedCounter(Counter, OrderedDict): ... pass ... >>> OrderedCounter('Mississippi').items() [('M', 1), ('i', 4), ('s', 4), ('p', 2)] Correct me if I'm wrong, but this crucially relies on the fact that Counter uses super: class Counter(dict): def __init__(*args, **kwds): ... super(Counter, self).__init__() ... That is, the magic trick works because >>>

Why 'T.super.toString()' and 'super::toString' use a synthetic accessor method?

走远了吗. 提交于 2019-12-04 23:54:33
Consider the following set of expressions: class T {{ /*1*/ super.toString(); // direct /*2*/ T.super.toString(); // synthetic Supplier<?> s; /*3*/ s = super::toString; // synthetic /*4*/ s = T.super::toString; // synthetic }} Which gives the following result: class T { T(); 0 aload_0 [this] 1 invokespecial java.lang.Object() [8] 4 aload_0 [this] 5 invokespecial java.lang.Object.toString() : java.lang.String [10] 8 pop // ^-- direct 9 aload_0 [this] 10 invokestatic T.access$0(T) : java.lang.String [14] 13 pop // ^-- synthetic 14 aload_0 [this] 15 invokedynamic 0 get(T) : java.util.function

Different ways of using __init__ for PyQt4

左心房为你撑大大i 提交于 2019-12-04 21:29:14
问题 So... I'm working on trying to move from basic Python to some GUI programming, using PyQt4. I'm looking at a couple different books and tutorials, and they each seem to have a slightly different way of kicking off the class definition. One tutorial starts off the classes like so: class Example(QtGui.QDialog): def __init__(self): super(Example, self).__init__() Another book does it like this: class Example(QtGui.QDialog): def __init__(self, parent=None): super(Example, self).__init__(parent)

Java wildcards and generics ? super T and ? extends T

大兔子大兔子 提交于 2019-12-04 19:42:21
when dealing with wildcards such as setting/adding a generic item to a certain container is it suggested to use something like this? void add(List<? super T> someList,someitem){ someList.add(someItem); } and when retrieving an item it is suggested to use something like this <T> void f1(List<? extends T> obj, T item) { obj.add(item); } What is the principle behind this? and when will I know if I should use this ? user1676688 you should have a look at the explanation of PECS principle What is PECS (Producer Extends Consumer Super)? In short, when you want to get information from an object, make

Determine whether super().__new__ will be object.__new__ in Python 3?

橙三吉。 提交于 2019-12-04 18:53:58
问题 Let's say I have some class that calls __new__ , how do I play well with the mro and call up to super classes' __new__ (with arguments) as necessary, but not call object.__new__ with additional arguments? E.g. this only works if you pass no arguments to the constructor: class A(object): def __new__(cls, *args, **kwargs): print("A.__new__ called") return super(A, cls).__new__(cls, *args, **kwargs) class B(object): def __new__(cls, *args, **kwargs): print("B.__new__ called") return super(B, cls

calling init for multiple parent classes with super? [duplicate]

点点圈 提交于 2019-12-04 16:35:45
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Can Super deal with multiple inheritance? Python inheritance? I have a class structure (below), and want the child class to call the __init__ of both parents. Is this possible to do in a 'super' way or is it just a terrible idea? class Parent1(object): def __init__(self): self.var1 = 1 class Parent2(object): def _init__(self): self.var2 = 2 class Child(Parent1, Parent2): def __init__(self): ## call __init__ of

Do I need to call [super viewDidUnload]?

独自空忆成欢 提交于 2019-12-04 09:31:26
I have seen some Apple examples that do call [super viewDidUnload]; and some that don't. I read an article (a few months ago so I dont recall the url) that said calling [super viewDidUnload]; was unnecessary but it didn't explain beyond that. Is there a definitive reason why or why not to tell super that the viewDidUnload ? And, (if it should be done) do I call super before setting all my properties to nil , after, or does it matter? - (void)viewDidUnload { // Is this necessary? // [super viewDidUnload]; self.tableDataSource = nil; self.titleLabel = nil; // Is it better to call super before or