instantiation

Guice creates Swing components outside of UI thread problem?

I'm working on Java Swing application with Google Guice as an IOC container. Things are working pretty well. There are some UI problems. When a standard L&F is replaced with Pushing pixels Substance L&F application is not running due to Guice's Swing components creation outside of UI thread. Is there a way to tell Guice to create Swing ...

gcc problem with explicit template instantiation?

It is my understanding that either a declaration or typedef of a specialization ought to cause a template class to be instantiated, but this does not appear to be happening with gcc. E.g. I have a template class, template class Foo {}; I write class Foo<double>; or typedef Foo<double> DoubleFoo; but after compilation th...

awakeFromNib and loadView execute for different instances

Hi, I'm trying to understand why: NSLog(@"self = %p", self); in awakeFromNib prints a different value than the same NSLog in viewDidLoad? This isn't a huge problem because I don't need the awakeFromNib but I would like to understand how it works. The code that creates the controller is the following: MyViewController *myViewCo...

Is it possible to create an enum whose instance can't be created but can be used for readonly purpose

I created an enum where I stored some table names. I want it to be used to get the name of the table like ds.Tables[BGuestInfo.TableName.L_GUEST_TYPE.ToString()]. public class a { public enum TableName : byte { L_GUEST_TYPE = 0 ,L_AGE_GROUP = 1 ,M_COMPANY = 2 ...

Instantiation vs. Typed reference

Just when I think Im starting to understand the basics, I find something that brings me right back to reality. In this case, typed reference. I found an example similar to this: class Worker { Boss boss; public void Advise(Boss pBoss) { this.boss = pBoss; } How can you reference methods within the Boss class if its not stati...

Create a new instance in a static function of an abstract class

abstract class db_table { static function get_all_rows() { ... while(...) { $rows[] = new self(); ... } return $rows; } } class user extends db_table { } $rows = user::get_all_rows(); I want to create instances of a class from a static method defined in the abstract pa...

Instantiating classes between jsp scriptlets

Is it possible to instantiate a class and then invoke its methods between scriptlets in JSP? I am getting errors and I don't know why (java class and methods are fine). Any other way to do the same (i just want a string from a method in a class)? ...

C# reflection instantiation

I am currently trying to create a generic instance factory for which takes an interface as the generic parameter (enforced in the constructor) and then lets you get instantiated objects which implement that interface from all types in all loaded assemblies. The current implementation is as follows: public class InstantiationFactory<T> ...

How to set default values to the properties of dynamically loaded types at runtime for XML serialization

I need to serialize dynamically loaded types' classes using XMLSerializer. When using XML serializer non initialized values are not being serialized. I dont have control over the assemblies I am working with so can not use XML attributes for specifying default values on properties. So I think I need to set all properties and sub propert...

Does Python copy value or reference upon object instantiation?

Hi folks, A simple question, perhaps, but I can't quite phrase my Google query to find the answer here. I've had the habit of making copies of objects when I pass them into object constructors, like so: ... def __init__(self, name): self._name = name[:] ... However, when I ran the following test code, it appears to not be necessa...

C# - Downside to Setting Initial Value in Declaration

Is there any downside to a class like: class Example1 { protected string UserId = (string)Session["user"]; } //versus class Example2 { protected string UserId; public Example2() { UserId = (string)Session["user"]; } } If I always want to set this value is there any downside to Example1? UPDATE: Session["user"] is se...

Manipulate method functionality call

Hello, is it possibly in c# to have some sort of base class functionality which is manipulated slightly based on the class. For instance say i have the following code (which will quite obviously not compile it's meant to only be for demonstrative purposes) class BaseFunctionality { public virtual bool adminCall public static str...

Calling a method on an object a bunch of times versus constructing an object a bunch of times

I have a List called myData and I want to apply a particular method (someFunction) to every element in the List. Is calling a method through an object's constructor slower than calling the same method many times for one particular object instantiation? In other words, is this: for(int i = 0; i < myData.Count; i++) myClass someObje...

Is there a benefit to storing an object in a variable before calling a method on it?

Example 1: SomeObject someObject = new SomeObject(); if (someObject.Method()) { //do stuff } //someObject is never used again vs Example 2: if (new SomeObject().Method()) { //do stuff } Is there any benefit to using the first method over the second, or vice versa? ...

calling class method (with constructors) without object instantiation in php

Hi everyone, Ive looked and tried but I can't find an answer. In PHP, is it possible to call a class' member function (when that class requires a constructor to receive parameters) without instantiating it as an object? A code example (which gives errors): <?php class Test { private $end=""; function __construct($value) {...

Private Variable Instantiation: When Defined or Within Constructor?

I don't know if this has been asked before, but we're having a discussion about it today at my job. Should private variables (that are shared/static) be instantiated when they are dimensioned/defined, or is it a better practice to do this inside of a constructor? For example, this seems perfectly fine to me... Public Class IpCam ...

In PHP 5 can I instantiate a class dynamically?

For example is something like this possible in PHP? class foo { public $something; } $class_name = "foo"; $f = new $class_name; ...

How to instantiate a large immutable type?

I have a type with about 40 properties (all value types) that represents a type of transaction for my business. An instance of this class corresponds to a row in my database. I would like to keep my class immutable since it will only ever be used for read operations, but I am not sure how to go about setting 40 properties during initia...

Initializing constructor from stored cache in C#

I'm not sure exactly how to describe this question, but here goes. I've got a class hierarchy of objects that are mapped in a SQLite database. I've already got all the non-trivial code written that communicates between the .NET objects and the database. I've got a base interface as follows: public interface IBackendObject { void Re...

How to create a value type or string type object at runtime using Reflection

Probably simple but could not figure out. I am loading an assembly at runtime and browsing through some classes and generating input controls for its properties. To create an instance of an object at runtime I am using: object o = PropertyType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, ...