instantiation

Instantiate class from name in MATLAB

限于喜欢 提交于 2019-11-30 08:47:18
I'm trying to list classes I created in some folder in my Matlab folder - using only their name (class name) as an example, I have a class called 'SimpleString' - and I'm aiming to instantiate an object from that class, if all I know is that its name is 'SimpleString' So in realtime, I'd like to find out what classes are in a folder (done), then be able to instantiate any of those classes (my question) Thanks You can use eval to instantiate the class using just the class name. instance = eval('SimpleString'); However, if you're simply iterating through all the m-files in a folder containing

deducing references to const from rvalue arguments

爷,独闯天下 提交于 2019-11-30 08:26:45
问题 Okay, this may seem like a silly question, but here it goes: template <typename T> void foo(T& x) { } int main() { foo(42); // error in passing argument 1 of 'void foo(T&) [with T = int]' } What is preventing C++ to instantiate the foo function template with T = const int instead? 回答1: The problem is that template type deduction has to work out an exact match, and in that particular case, because of the reference in the signature, an exact match requires an lvalue. The value 42, is not an

Guice creates Swing components outside of UI thread problem?

ぐ巨炮叔叔 提交于 2019-11-30 05:27:14
问题 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 components in the UI thread? Maybe I should create custom providers which will return Swing components after SwingUtilities.invokeAndWait(Runnable) creates

Can a static nested class be instantiated in Java?

点点圈 提交于 2019-11-29 22:22:09
From Oracle's Java tutorials I've found this text: As with class methods and variables, a static nested class is associated with its outer class. And like static class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class — it can use them only through an object reference. Note: A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for

Instantiating Rhinoscript Native Objects from Java/Scala

喜欢而已 提交于 2019-11-29 16:39:53
I'm trying to improve the performance of a javascript snippet evaluator . These script snippets can reference any number of variables that exist in a string-keyed map of json-like object graphs (IE: Json AST). I'm using JDK 1.6 and the embedded Rhinoscript engine (v1.6R2). Currently, processing takes the form: Snippet is parsed to discover the names of referenced variables Variables are retrieved from the map and serialized to a json string Json string is assigned to a similarly named variable at the start of the script Evaluate augmented script I'm trying to figure out how to skip the json

How to instantiate an object in TypeScript by specifying each property and its value?

六眼飞鱼酱① 提交于 2019-11-29 13:52:27
问题 Here's a snippet in which I instantiate a new content object in my service: const newContent = new Content( result.obj.name result.obj.user.firstName, result.obj._id, result.obj.user._id, ); The problem is that this way of object instantiation relies on the order of properties in my content model. I was wondering if there's a way to do it by mapping every property to the value I want to set it to, for example: const newContent = new Content( name: result.obj.name, user: result.obj.user.

How should I select which concrete implementation should be instantiated based on the user choice?

冷暖自知 提交于 2019-11-29 12:49:59
I have an interface Fruit with two implementations Apple and Banana . I want to create a Fruit instance. The choice whether the concrete implementation should be an Apple or a Banana should be made by the user. I did not yet design the user interface, so there is no restriction how this choice is made by the user. I know there are the following options: usage of the abstract factory pattern usage of reflection to create an instance from a given class name usage of reflection to create an instance from a given class object What are the pros and cons of these options? Please note that while

InstantiationException when using subclass of EditTextPreference

*爱你&永不变心* 提交于 2019-11-29 12:47:49
Assume, I have a subclass of EditTextPreference called PasswordProtectedEditTextPreference. This subclass basically shows a password dialog before one can edit the preference by the EditTextPreference 's own dialog. Now I define the preference in the corresponding preferences.xml like this: <edu.myproject.pwprefs.PasswordProtectedEditTextPreference android:key="pref_password" android:title="@string/pref_password_title" android:summary="@string/pref_password_summary" android:dialogTitle="@string/pref_password_dialog_title" android:dialogMessage="@string/pref_password_dialog_message"> </edu

Unity 2D C# Instantiate sprite on canvas. Can't find what's wrong

巧了我就是萌 提交于 2019-11-29 12:08:23
I read many questions about this, but I still can't find what my problem is... I'm trying to instantiate a prefab at the canvas. It is compose of a button and a sprite. The button looks ok, but the sprite is not visible at the Game (but is visible at the Scene). I'm doing something wrong, but I can't see what... [SerializeField] GameObject finishedLevel; private void Start() { finishedLevel = Instantiate(finishedLevel, transform.position, transform.rotation); finishedLevel.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, false); } SpriteRenderer is not made to be used

Automatically separate class definitions from declarations?

◇◆丶佛笑我妖孽 提交于 2019-11-29 11:35:33
I am using a library that consists almost entirely of templated classes and functions in header files , like this: // foo.h template<class T> class Foo { Foo(){} void computeXYZ() { /* heavy code */ } }; template<class T> void processFoo(const Foo<T>& foo) { /* more heavy code */ } Now this is bad because compile times are unbearable whenever I include one of those header files (and actually I include many of them in each of my compilation units). Since as a template parameter I only use one or two types anyway I am planning to create, for each library header file, a file that contains only