instance

Is there a name for “this” in Java?

泪湿孤枕 提交于 2019-11-29 01:06:36
Eclipse will give an error, "The left-hand side of an assignment must be a variable", when I try something like: public class Thing{ String a1; int a2; public void meth(){ Thing A = new Thing(); this = A; } } I had to assign each variable ( this.a1 = A.a1; this.a2 = A.a2; ) as a work around. Are there other ways to do this without going through each variable field? And if this is not a variable what is it called? this is a pseudo-variable that points to the current instance of the object, it can not be reassigned. It's also considered a keyword in the language, according to section §3.9 of the

How can I call a static method on a variable class?

梦想与她 提交于 2019-11-29 00:57:26
I'm trying to make some kind of function that loads and instantiates a class from a given variable. Something like this: <?php function loadClass($class) { $sClassPath = SYSPATH."/classes/{$class}.php"; if (file_exists($sClassPath)) { require_once($sClassPath); $class = $class::getInstance(); } } ?> If I use it like this: <?php loadClass('session'); ?> It should include and instantiate the session class. BTW: the static getInstance function comes from this code: <?php function getCallingClass() { $backtrace = debug_backtrace(); $method = $backtrace[1]['function']; $file = file($backtrace[1][

Writing to a static variable in an instance method, why is this a bad practice?

ぃ、小莉子 提交于 2019-11-28 23:19:17
I am a little confused here with this findbugs warning in eclipse. public class MyClass { public static String myString; } public class AnotherClass { public void doSomething() { MyClass.myString = "something"; } } This gives me a findbugs warning "write to static field from instance method", however this does not give me a warning: public class MyClass { public static String myString; } public class AnotherClass { public void doSomething() { doAnotherThing(); } public static doAnotherThing() { MyClass.myString = "something"; } } How is this any different?, and why is writing to a static

Get Instance ID of an Object in PHP

你说的曾经没有我的故事 提交于 2019-11-28 20:19:13
I've learn a while ago on StackOverflow that we can get the "instance ID" of any resource , for instance: var_dump(intval(curl_init())); // int(2) var_dump(intval(finfo_open())); // int(3) var_dump(intval(curl_init())); // int(4) var_dump(intval(finfo_open())); // int(5) var_dump(intval(curl_init())); // int(6) I need something similar but applied to classes: class foo { public function __construct() { ob_start(); var_dump($this); // object(foo)#INSTANCE_ID (0) { } echo preg_replace('~.+#(\d+).+~s', '$1', ob_get_clean()); } } $foo = new foo(); // 1 $foo2 = new foo(); // 2 The above works but I

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

*爱你&永不变心* 提交于 2019-11-28 19:40:12
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": [ { "Effect": "Allow", "Action": [ "ec2:DescribeImages", "ec2:DescribeKeyPairs", "ec2:DescribeSecurityGroups", "ec2:DescribeAvailabilityZones" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "ec2:DescribeInstances","ec2:RunInstances", "ec2:TerminateInstances", "ec2:StartInstances", "ec2:StopInstances", "DescribeInstanceAttribute", "DescribeInstanceStatus"

How to get an existing websocket instance

扶醉桌前 提交于 2019-11-28 19:20:22
问题 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 created. Everytime a connection is established to the websocket endpoint, I'm adding the corresponding session to a list, which I could be able to access outside. But the problem I had is, when I'm accessing this created websocket endpoint to which all

Difference between reference and instance in javascript

元气小坏坏 提交于 2019-11-28 19:15:59
问题 Sometimes I hear people say "a reference to a object" and some say "a instance of a object" What is the difference? 回答1: A variable will hold a reference to an instance of an object. The actual object is an instance . The variable/variables used to access the object hold the references to it. 回答2: Instance of an object (or, perhaps more accurately phrased when talking about languages that have the notion, of a class) is an object that has been created and exists in memory. For example, when

WPF Enforce only ONE instance of application

故事扮演 提交于 2019-11-28 16:42:34
问题 How do I allow only one instance of a WPF application to run? Thanks. 回答1: http://blogs.microsoft.co.il/blogs/arik/archive/2010/05/28/wpf-single-instance-application.aspx Doesn't require VB.DLL as some other examples advise. Has WPF sample code. Passes any cmd line args to initial instance. 回答2: Try this: Single instance application. Ive used the second method and it works fine. 回答3: I use this helper method and call it from the application.startup event Public Sub

new Backbone.Model() vs Backbone.Model.extend()

为君一笑 提交于 2019-11-28 16:11:55
问题 I'm new to JS and Backbone What's the difference between these two? TestModel = new Backbone.Model({ title: "test title" }) TestModel = Backbone.Model.extend({ title: "test title" }) 回答1: There is a basic difference, which in short can be described as "the difference between the project of a house and the house itself". For expert programmers I would just say that "new Backbone.Model" returns an object instance, but "Backbone.Model.extend" returns a constructor function FIRST: a new object (i

Does OO Javascript have a `to_bool` or `__len__` equivalent?

倾然丶 夕夏残阳落幕 提交于 2019-11-28 14:31:51
Does OO JS have a mechanism for casting instance objects to boolean? I would like to be able to use custom instance objects directly in conditionals, and make assertions along the lines of !!(new Foo(0)) === false , !!(new Foo(1)) === true . Python has __nonzero__ and __len__ (see here ) Ruby has to_bool . How does JS do this for String literals "" and zero 0 ? No, JS does not provide a trap method for casting to boolean. Truthiness of a value is statically determined by the language rules and cannot be changed. You should give your instances a method to be explicitly invoked like isValid() ,