constructor

Autowire a parameterized constructor in spring boot

橙三吉。 提交于 2020-07-16 07:23:19
问题 I am not able to autowire a bean while passing values in paramterized constructor. How to call the parameterized constructor using SpringBoot? @Component public class MainClass { public void someTask() { AnotherClass obj = new AnotherClass(1, 2); } } //Replace the new AnotherClass(1, 2) using Autowire? @Component public class AnotherClass { private int number,age; public AnotherClass(int number, int age) { super(); this.number = number; this.age = age; } } I want to autowire "AnotherClass"

Can I initialize an STL vector with 10 of the same integer in an initializer list?

。_饼干妹妹 提交于 2020-07-04 06:07:50
问题 Can I initialize an STL vector with 10 of the same integer in an initializer list? My attempts so far have failed me. 回答1: I think you mean this: struct test { std::vector<int> v; test(int value) : v( 100, value ) {} }; 回答2: Use the appropriate constructor, which takes a size and a default value. int number_of_elements = 10; int default_value = 1; std::vector<int> vec(number_of_elements, default_value); 回答3: If you're using C++11 and on GCC, you could do this: vector<int> myVec () {[0 ... 99]

Why default argument constructor is called as default constructor

三世轮回 提交于 2020-07-03 03:02:53
问题 Class A { public: A(int i = 0, int k = 0) {} // default constructor WHY ?? ~A() {} }; int main() { A a; // This creates object using defined default // constructor but the constructor still has two arguments A b(1,2); // Called as parametrized one } Why this default argument constructor is default constructor. Why it is not called Parametrized constructor or default parametrized constructor because even if this constructor is called with no arguments it does contain two arguments ?? Is there

Prism/WPF views/viewmodels being created twice

两盒软妹~` 提交于 2020-06-29 03:48:34
问题 I have a Prism 7 / WPF / MVVM app that is configured with AutowireViewModel="True" in the views that have a viewmodel. Most of my view models have dependencies that I have configured in the Prism Unity container and these dependencies are injected into the viewmodel contructor. I do not explicitly create instances of views/viewmodels in the code behind anywhere. I also do not set the data context in XAML i.e. using DataContext element or d:DataContext). The only references in the XAML are to

How to fix “CA1810: Initialize reference type static fields inline” with an abstract base…?

风流意气都作罢 提交于 2020-06-27 08:56:33
问题 Here's the simplified parts of code that I have: abstract class DataManager<TValue> { protected static Dictionary<string, TValue> Values; } and then I have: class TextManager : DataManager<string> { static TextManager() { Values = ... // Fill with data } } And, now I'm getting CA1810. I see a few solutions, like making Values public and setting them elsewhere, but I don't like that, or making a static method in TextManager to do the same thing, but is invoked when the program starts, but I

How to fix “CA1810: Initialize reference type static fields inline” with an abstract base…?

浪尽此生 提交于 2020-06-27 08:56:20
问题 Here's the simplified parts of code that I have: abstract class DataManager<TValue> { protected static Dictionary<string, TValue> Values; } and then I have: class TextManager : DataManager<string> { static TextManager() { Values = ... // Fill with data } } And, now I'm getting CA1810. I see a few solutions, like making Values public and setting them elsewhere, but I don't like that, or making a static method in TextManager to do the same thing, but is invoked when the program starts, but I

get parameters from URL in controller constructor

自闭症网瘾萝莉.ら 提交于 2020-06-26 07:57:28
问题 I need to write some code to find an ID in my database of a Project. Users are coupled to a project and all the projects have a lot of connections to other objects, such as Sessions. Now I need to check before running any Actions, if the user trying to access the Session, is connected to the same project as the session is connected to. For this i want to use an [Attribute] on the Actions. MVC: creating a custom [AuthorizeAttribute] which takes parameters? This question and answer got me

What makes enum in java non instantiable?

那年仲夏 提交于 2020-06-25 07:36:10
问题 I know that an enum enum Year { First, Second, Third, Fourth; } gets converted into final class Year extends Enum<Year> { public static final Year First = new Year(); public static final Year Second = new Year(); public static final Year Third = new Year(); public static final Year Fourth = new Year(); } When I tried to instantiate enum (not class) I got compile time error as: error: enum types may not be instantiated Year y = new Year(); As per my knowledge a private constructor makes a

Why is there no need to mark the move constructor of a type with a deleted copy constructor as deleted?

老子叫甜甜 提交于 2020-06-23 11:06:57
问题 Consider std::mutex . I understand why std::mutex should not be movable. But its copy constructor is clearly marked as deleted, but I have not seen such a declaration for its move constructor. So why does cppreference say std::mutex is not movable? As per the documentation(https://en.cppreference.com/w/cpp/language/move_constructor), there are many preconditions that are not fulfilled that prevent the implicit move constructor. But I could not find the reason for this question. I would be

Why is there no need to mark the move constructor of a type with a deleted copy constructor as deleted?

♀尐吖头ヾ 提交于 2020-06-23 11:06:48
问题 Consider std::mutex . I understand why std::mutex should not be movable. But its copy constructor is clearly marked as deleted, but I have not seen such a declaration for its move constructor. So why does cppreference say std::mutex is not movable? As per the documentation(https://en.cppreference.com/w/cpp/language/move_constructor), there are many preconditions that are not fulfilled that prevent the implicit move constructor. But I could not find the reason for this question. I would be