Questions tagged [instance]

In object-oriented programming an instance is an occurrence or a copy of an object, whether currently executing or not.

Instances of a class share the same set of attributes, yet will typically differ in what those attributes contain. For example, a class "Employee" would describe the attributes common to all instances of the Employee class. For the purposes of the task being solved Employee objects may be generally alike, but vary in such attributes as "name" and "salary".

Related tags:

5388 questions
16
votes
5 answers

One-step object creation and property initialization in Swift?

Is there a way to assign property values to a class instance even if it is not a parameter in the init constructor? For example, in C# I can do this: public class Student { public string firstName; public string lastName; } var student1 = new…
TruMan1
  • 33,665
  • 59
  • 184
  • 335
16
votes
12 answers

How to get instance of a specific class in PHP?

I need to check if there exists an instance of class_A ,and if there does exist, get that instance. How to do it in PHP? As always, I think a simple example is best. Now my problem has become: $ins = new class_A(); How to store the instance in a…
user198729
  • 61,774
  • 108
  • 250
  • 348
16
votes
8 answers

Is it possible for instance to destroy/delete self?

NOTE: I'm interested in C#,Java and C++ most, but as this is the more academic question any language will do. I know that this problem is solvable from outside, by using appropriate methods of given languages (calling free, Dispose, or by removing…
jnovacho
  • 2,825
  • 6
  • 27
  • 44
16
votes
5 answers

How to test if a class attribute is an instance method

In Python I need to efficiently and generically test whether an attribute of a class is an instance method. The inputs to the call would be the name of the attribute being checked (a string) and an object. hasattr returns true regardless of whether…
Richard Dorman
  • 23,170
  • 16
  • 45
  • 49
15
votes
8 answers

Ever need to destroy a singleton instance?

By using a singleton, only one instance of it can be created. Do we ever need to destroy that instance? I have a singleton DBManager, which manages a JDBC connection and query operations. By calling its static newInstance method, I can get the…
chance
  • 6,307
  • 13
  • 46
  • 70
15
votes
2 answers

How to get an existing websocket instance

I'm working on an application that uses Websockets (Java EE 7) to send messages to all the connected clients asynchronously. The server (Websocket endpoint) should send these messages whenever a new article (an engagement modal in my app) is…
Aryan Venkat
  • 679
  • 1
  • 10
  • 34
15
votes
2 answers

How to access a static method from a instance method in mongoose?

How to access a static method from a instance method in mongoose? I have a job model named Job. From a instance method job.start I want to call the static method Job.someStatic(). How do I get the reference to the Job, from the "this" in the…
Totty.js
  • 15,563
  • 31
  • 103
  • 175
15
votes
5 answers

Java: super.clone() method and inheritance

I have a quick question regarding the clone() method in Java, used as super.clone() in regard to inheritance - where I call the clone() method in the parent class all the way up from the button. The clone() method is supposed to return a copy of…
Shuzheng
  • 11,288
  • 20
  • 88
  • 186
15
votes
4 answers

How to check application runs in AWS EC2 instance

How can I check which platform my app runs, AWS EC2 instance, Azure Role instance and non-cloud system? now I do that like this: if(isAzure()) { //run in Azure role instance } else if(isAWS()) { //run in AWS EC2 instance } else { //run in…
Jimmy
  • 153
  • 1
  • 1
  • 5
14
votes
3 answers

What is more efficient StringBuffer new() or delete(0, sb.length())?

It is often argued that avoiding creating objects (especially in loops) is considered good practice. Then, what is most efficient regarding StringBuffer? StringBuffer sb = new StringBuffer(); ObjectInputStream ois = ...; for (int i=0;i<1000;i++)…
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
14
votes
4 answers

What resources does an instance of a class use?

How efficient is python (cpython I guess) when allocating resources for a newly created instance of a class? I have a situation where I will need to instantiate a node class millions of times to make a tree structure. Each of the node objects should…
Alex
  • 1,442
  • 2
  • 11
  • 16
14
votes
1 answer

What exactly are the losses in Matterport Mask-R-CNN?

I use Mask-R-CNN to train my data with it. When i use TensorBoard to see the result, i have the loss, mrcnn_bbox_loss, mrcnn_class_loss, mrcnn_mask_loss, rpn_bbox_loss, rpn_class_loss and all the same 6 loss for the validation: val_loss,…
Mob
  • 409
  • 1
  • 5
  • 14
14
votes
3 answers

Is there a syntax for creating an anonymous subclass in C#?

Can I create instance of abstract class in C#/.net like in Java ? Additional Info I think a lot of us does not understand what do I mean? So, In java I can create abstract class like this : Simple abstract class : /** * @author jitm * @version…
jitm
  • 2,569
  • 10
  • 40
  • 55
14
votes
4 answers

Checking if a variable belongs to a class in python

I have a small class which is as follows : class Gender(object): MALE = 'M' FEMALE = 'F' I have a parameter variable which can be only M or F.To ensure it is only that, I do the following : >>> parameter = 'M' >>> if parameter not in…
Amistad
  • 7,100
  • 13
  • 48
  • 75
14
votes
1 answer

How to hide instances in EC2 based on tag - using IAM?

I want to create a new user in IAM, and allow him to be able to create new EC2 instances, but be able to view/administer only those instances that he creates. Is this possible with IAM? This is the group policy I tried: { "Statement": [ { …