- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
@try {
if ([segue.identifier isEqualToString:@"taskListSegue"])
{
MindMapInformationViewController_iPhone *taskListContentController = [segue destinationViewController];
int selectedIndexPath = [[self.tableView indexPathForSelectedRow] row];
MindMap *newMindMap;
newMindMap = [mindmaps objectAtIndex:selectedIndexPath];
FileManager *fileManager = [[[FileManager alloc] init] autorelease];
[fileManager readFile:newMindMap.pathToMindmapAtDevice parsing:YES];
NSMutableArray *taskArray = [fileManager getArray];
[taskListContentController setTasksOfSelectedMindmap:taskArray];
}
}
@catch (NSException *exception) {
}
}
-(void)setTasksOfSelectedMindmap:(NSMutableArray *)tasks {
@try {
[self initComponents];
if (tasks != nil) {
taskArray = tasks;
}
}
@catch (NSException *exception) {
}
}
-(void)initComponents {
@try { …Run Code Online (Sandbox Code Playgroud) 这是superGuido 内置的纯python实现,用于说明目的.我需要对Super下面的课程实施做一些澄清
在下面的代码中调用someobj.__mro__将不起作用.看到我对这条线的评论.内置super只是一个错误被抛出.
TypeError: super(type, obj): obj must be an instance or subtype of type
题:
我的问题是,首先要有这条线的意图是什么?
因此,如果传入的对象不是传入类的实例,那么开始使用对象的mro ...为什么?
class Super(object):
def __init__(self, type, obj=None):
self.__type__ = type
self.__obj__ = obj
def __get__(self, obj, type=None):
if self.__obj__ is None and obj is not None:
return Super(self.__type__, obj)
else:
return self
def __getattr__(self, attr):
if isinstance(self.__obj__, self.__type__):
starttype = self.__obj__.__class__
else:
starttype = self.__obj__ ## This line does not work
mro = …Run Code Online (Sandbox Code Playgroud) 我有一个关于 java 中 super 关键字的问题。请按照下面的示例操作:
public class Circle {
private double radius;
private double area;
public void setRadius(double radius){
this.radius = 1;
}
public double getRadius(){
return this.radius;
}
public void setArea(double radius){
this.area = area;
}
public double getArea(){
return this.area = Math.PI * radius * radius;
}
}
public class Cylinder extends Circle {
private double height;
public Cylinder(){
super();
height = 1;
}
public Cylinder(double height){
super();
this.height = height;
}
public Cylinder(double radius, double height){
super(); …Run Code Online (Sandbox Code Playgroud) 来自Java,我对调用基类构造函数(或super())有点困惑。我有 2 个类:Player(抽象类)和HumanPlayer ,它是 Player 的子类。现在,我有一个 Player 的构造函数,其声明如下:
Player(string name, list<Point> points);
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试实现这样的东西:
HumanPlayer() {
string name = get name from user...
list<Point> points = get points from user...
...
...
...
super(name, points);
}
Run Code Online (Sandbox Code Playgroud)
对于c++来说真的很陌生,很难理解它的语法。问候,
我们有这样的构造函数:
public statusArea()
{
super();
add(pageIdentifier);
}
Run Code Online (Sandbox Code Playgroud)
我们为什么要打电话super呢?
我正在编写演示继承使用的程序,并且我使用 super() 关键字创建了一个变量。我现在试图将该变量的值放入一个调用它的新方法中,以便我可以在主方法中调用该方法以在其他类中使用它的值。
这是相关的代码:
食品班(超班)
public class Food {
//field that stores the name of the food
public String name;
//constructor that takes the name of the food as an argument
public Food(String name){
this.name = name;
}
public String getName() {
return name;
}
}
Run Code Online (Sandbox Code Playgroud)
肉类类(带有 super 关键字的子类)
public class Meat extends Food
{
public Meat() {
super("Meat");
}
public String getName() {
return //get super() value??;
}
}
Run Code Online (Sandbox Code Playgroud)
主班
public class Main {
public static void main(String[] args) …Run Code Online (Sandbox Code Playgroud) 比如说我有一Circle堂课:
static final double DEFAULT_RADIUS = 1.0;
Circle(Point centre, double radius) {
this.centre = centre;
this.radius = radius;
}
Circle(Point centre) {
this(centre, Circle.DEFAULT_RADIUS);
}
// ...
Run Code Online (Sandbox Code Playgroud)
然后在ColoredCircle,一个子类Circle:
ColoredCircle(Point centre, Color color, double radius) {
super(centre, radius);
this.color = color;
}
ColoredCircle(Point centre, Color color) {
// ???
}
Run Code Online (Sandbox Code Playgroud)
的第二个构造函数应该ColoredCircle怎么做?
this(centre, color, Circle.DEFAULT_RADIUS);super(centre, Circle.DEFAULT_RADIUS); this.color = color;我认为两者都可以,但这会导致“更干净的代码”?
class Base(object):
def __init__(self):
self.fname="MS"
self.lname="Dhoni"
class Child(Base):
def __init__(self):
self.fname="kohli"
super(Base).__init__()
Run Code Online (Sandbox Code Playgroud)
上面代码中 super 方法的用途是什么甚至评论super(Base).__init__()我正在获取输出kohli
请解释
我有一个带有具体方法的 Python ABC(我们称之为A)__init__(),以及一个实现这个 ABC 的类(我们称之为B)。据我了解,我不应该能够实例化 ABC。
问题:类函数super().__init__()内部的调用为什么以及如何工作?我假设创建了父类的一个实例 - 在本例中是 ABC。__init__Bsuper()
from abc import ABC, abstractmethod
from util.fileManager import FileManager
class A(ABC):
def __init__(self):
self.file_manager = FileManager() # Composition object
...
Run Code Online (Sandbox Code Playgroud)
from interfaces.A import A
class B(A):
def __init__(self):
super().__init__()
...
Run Code Online (Sandbox Code Playgroud)
Python 中的“super”有什么作用?- super().__init__() 和显式超类 __init__() 之间的区别
正如你们许多人可能已经看到的那样,这个问题实际上可以归结为super()Python 中的作用。接受我标记的答案,我真的想指出@KarlKnechtel评论中的链接,因为它帮助我进一步了解情况。
class Foo(list):
def bar(self):
return super().__getitem__(slice(None))
def baz(self):
return super()
a = Foo([0, 1, 2, 3])
print(a.bar()) # [0, 1, 2, 3]
print(a.baz()) # <super: <class 'Foo'>, <Foo object>>
# a.bar() provides a copy of the underlying list as can be seen from the fact that each result of a.bar() has a different id
print(id(a.bar())) # id1
print(id(a.bar())) # id2 != id1
Run Code Online (Sandbox Code Playgroud)
我最近有一个用例,我需要子类化list并需要从子类 ( ) 内访问底层列表Foo。我以为super()会提供基础列表,但没有。相反,我必须super().__getitem__(slice(None))提供底层列表的副本。如何直接访问底层列表?我的理解中缺少什么super()?
非常感谢!
super ×10
java ×4
python ×4
constructor ×2
inheritance ×2
abc ×1
c++ ×1
cocoa ×1
list ×1
objective-c ×1
oop ×1
python-3.x ×1
radix ×1
subclass ×1
superclass ×1
this ×1
viewdidload ×1