instantiation

InstantiationException when using subclass of EditTextPreference

杀马特。学长 韩版系。学妹 提交于 2019-12-18 07:14: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="

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

给你一囗甜甜゛ 提交于 2019-12-18 07:14:29
问题 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

Automatically separate class definitions from declarations?

痞子三分冷 提交于 2019-12-18 07:05:02
问题 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

Generics wildcard instantiation

六眼飞鱼酱① 提交于 2019-12-18 06:08:25
问题 I was reviewing someone else's code the other day and I came across a line that raised some concern. To simplify, say I have a generic Class A and an abstract Class B. Is the following instantiation allowed and if so, why? Object obj = new A<? extends B>(); I personally have never seen an instantiation like the above, although a declaration such as A<? extends B> obj = null; would certainly hold. I've always used the wildcard in generics to declare method parameters, so I may just not have

How to instantiate a class in Objective-C that don't inherit from NSObject

余生长醉 提交于 2019-12-18 03:08:25
问题 Given this: Person.h: @interface Person { } - (void) sayHello; @end Person.m: #import "Person.h" @implementation Person - (void)sayHello { printf("%s", "Steve"); } @end How do you instantiate the Person? I tried this: Person *p = [Person new]; That doesn't work, nor this: Person *p = [Person alloc]; [UPDATE] I forgot to tell, I already tried inheriting from NSObject, the new and alloc works. I'm just curious if we can instantiate a class that doesn't inherit from NSObject? 回答1: You absolutely

Generics and Class.forName

人盡茶涼 提交于 2019-12-17 18:28:03
问题 I would like to create an instance of a specified class using its name. My code is shown below. I get a compiler warning. Am I doing this the right way? Is it even possible to use the name of a class and get an instance of that type back, as I don't think there is any way of the compiler knowing what the type should be? public static <T> T create(final String className) { try { final Class<?> clazz = Class.forName(className); //WARNING: Type safety: Unchecked cast from capture#2-of ? to T

Why is it possible to instantiate a struct without the new keyword?

半世苍凉 提交于 2019-12-17 17:31:31
问题 Why are we not forced to instantiate a struct, like when using a class? 回答1: The why is simply - because the spec says so . The how is a matter of ensuring that the entire block of memory is "definitely assigned", which means: assigning a value to each field of the struct. However, this requires 2 nasty things: public fields (almost always bad) mutable fields (generally bad in a struct) so in most best-practice cases , you do need to use the new(...) syntax, to invoke the constructor (or to

What's the difference between dict() and {}?

安稳与你 提交于 2019-12-17 15:34:11
问题 So let's say I wanna make a dictionary. We'll call it d . But there are multiple ways to initialize a dictionary in Python! For example, I could do this: d = {'hash': 'bang', 'slash': 'dot'} Or I could do this: d = dict(hash='bang', slash='dot') Or this, curiously: d = dict({'hash': 'bang', 'slash': 'dot'}) Or this: d = dict([['hash', 'bang'], ['slash', 'dot']]) And a whole other multitude of ways with the dict() function. So obviously one of the things dict() provides is flexibility in

How to instantiate an object with a private constructor in C#?

微笑、不失礼 提交于 2019-12-17 11:25:25
问题 I definitely remember seeing somewhere an example of doing so using reflection or something. It was something that had to do with SqlParameterCollection which is not creatable by a user (if I'm not mistaken). Unfortunately cannot find it any longer. Can anyone please share this trick here? Not that I consider it a valid approach in development, I'm just very interested in the possibility of doing this. 回答1: // the types of the constructor parameters, in order // use an empty Type[] array if

How to instantiate an object with a private constructor in C#?

﹥>﹥吖頭↗ 提交于 2019-12-17 11:24:39
问题 I definitely remember seeing somewhere an example of doing so using reflection or something. It was something that had to do with SqlParameterCollection which is not creatable by a user (if I'm not mistaken). Unfortunately cannot find it any longer. Can anyone please share this trick here? Not that I consider it a valid approach in development, I'm just very interested in the possibility of doing this. 回答1: // the types of the constructor parameters, in order // use an empty Type[] array if