instance

How to call a method of another Class?

谁说我不能喝 提交于 2019-11-28 10:09:53
问题 EDIT2: I try to summarize my problem and the solutions: I've got a TableViewController named DetailedViewController. My intention was to activate TouchesBegan to recognize actions like sliding etc, and normally, the method touchesbegan is replaced with the DidSelectRow method. In many posts on stackoverflow, subclassing the UITableView is the only possibility to realize this. So i created a SpecificTable with .xib file and i used this as a subclass of UITableViewController by adding the

When to use static variables/methods and when to use instance variables/methods in Java? [closed]

我的梦境 提交于 2019-11-28 09:58:44
i would like to ask the question when it would be advantageous to use static variables/methods or in the other case instance variables/methods in Java? I know that it depends on the certain case (like programming util-classes as static methods), but can we declare something like a general strategy? TheLostMind At novice level : Use instance variables when : Every variable has a different value for different object. E.g. name of student, roll number etc.. use static variables when : The value of the variable is independent of the objects (not unique for each object). E.g. number of students.

Java Reflection: get instances of a given class found by entering its name?

十年热恋 提交于 2019-11-28 09:48:21
Is it possible to get all instances of a class by entering this class's name as a string? Something like this? var instances = Reflection.findClass("com.someone.MyClass").getInstances(); Any feedback is appreciated. Thanks. No, there's nothing like that available. If you hook into the debugging API you may be able to do it, but not when running "normally". I don't know of a way of doing this at runtime, but, if you are happy doing it 'offline', you can do the following: Take a heap dump Load the heap dump into Eclipse MAT Open an OQL pane, and enter a command such as select * from com.someone

Getting all instances of a class [duplicate]

大憨熊 提交于 2019-11-28 09:42:54
Possible Duplicate: Is there a simple way of obtaining all object instances of a specific class in Java In java, is there any possible way to get all the instances of a certain class? You can use a Factory static initializer when you instantiate your class ( Singleton pattern ) and then add each generated instance in the factory constructor to a List ... Something like this : class MyObject { private static List instances = new ArrayList(); public static MyObject createMyObject() { MyObject o = new MyObject(); instances.add(new java.lang.ref.WeakReference(o)); return o; } public static List

Problem in instance variable initialization

。_饼干妹妹 提交于 2019-11-28 09:33:07
Heres some sample code, class Base { private int val; Base() { val = lookup(); } public int lookup() { //Perform some lookup // int num = someLookup(); return 5; } public int value() { return val; } } class Derived extends Base { private int num = 10; public int lookup() { return num; } } class Test { public static void main(String args[]) { Derived d = new Derived(); System.out.println("d.value() returns " + d.value()); } } output: d.value() returns 0 // I expected 10 as lookup() is overridden, but not 0! can someone clarify this? The initialization of Derived 's instance variables has not

A question regarding string instance uniqueness in python

筅森魡賤 提交于 2019-11-28 09:13:01
问题 I was trying to figure out which integers python only instantiates once (-6 to 256 it seems), and in the process stumbled on some string behaviour I can't see the pattern in. Sometimes, equal strings created in different ways share the same id, sometimes not. This code: A = "10000" B = "10000" C = "100" + "00" D = "%i"%10000 E = str(10000) F = str(10000) G = str(100) + "00" H = "0".join(("10","00")) for obj in (A,B,C,D,E,F,G,H): print obj, id(obj), obj is A prints: 10000 4959776 True 10000

Why is instance variable behaving like a class variable in Python? [duplicate]

守給你的承諾、 提交于 2019-11-28 08:50:01
问题 Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument I have the following code: class Node(object): def __init__(self, value = 0, children = {}): self.val = value self.children = children def setChildValue(self, index, childValue): self.children[index] = Node(childValue) n = Node() n.setChildValue(0,10) print n.children n2 = Node() print n2.children And it prints: {0: <__main__.Node object at 0x10586de90>} {0: <__main__.Node object at 0x10586de90>} So my question

NSClassFromString returns nil

浪子不回头ぞ 提交于 2019-11-28 08:20:12
Why does NSClassFromString return nil ? As per the definition it has to return class name. How should I take care to rectify this problem? I need to instantiate a class from string and call the method, which is in the class, using the instance created. This is how my code looks like: id myclass = [[NSClassFromString(@"Class_from_String") alloc] init]; [myclass method_from_class]; But the method_from_class function is not being called, control is not going into it. And my code is error free. Any idea how to solve this in Objective-C? The Documentation for the function says : Return Value The

Python check instances of classes

泄露秘密 提交于 2019-11-28 07:54:38
Is there any way to check if object is an instance of a class? Not an instance of a concrete class, but an instance of any class. I can check that an object is not a class, not a module, not a traceback etc., but I am interested in a simple solution. isinstance() is your friend here. It returns a boolean and can be used in the following ways to check types. if isinstance(obj, (int, long, float, complex)): print obj, "is a built-in number type" if isinstance(obj, MyClass): print obj, "is of type MyClass" Hope this helps. Have you tried isinstance() built in function? You could also look at

Perl - call an instance of a class

梦想的初衷 提交于 2019-11-28 07:50:42
问题 Is there way to catch the event of calling an instance of a Perl class? my $obj = ExampleClass->new(); $obj(); # do something without producing error I would like to be able to handle this from within the class/module definition. Something similar to the __call__ method in Python, or the __call metamethod in Lua. 回答1: I'm still not sure what the use case is, but you can overload the class to handle code dereferencing. package ExampleClass; use overload '&{}' => \&__call__; # Or an anon sub.