59 questions
1
vote
1
answer
97
views
Subclassing and overriding Java class with protected field access
The scala project is depending on the Java lib that I cannot modify. I need to extend one of the Java classes and override method, however I have issues with protected visibility:
package com.a;
...
1
vote
1
answer
112
views
How to Instantiate a Custom Data Type with Record Syntax and Multiple Constructors
I'm new to Haskell and can't figure out if I'm mixing up concepts or if it's just a syntax error eluding me.
I have a function which expects to return an "Expr" type - a custom data type I'...
0
votes
0
answers
46
views
Out of Memory due to multiple consumers ActiveMQ
I am using DefaultMessageListenerContainer as below :
private static final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MessageConsumer.class);
public ...
0
votes
3
answers
626
views
I keep getting "error: cannot find symbol" when trying to do constructor chaining
So this is the part of my code that contains the constructors. As you can see, the purpose is to have the constructors take in less parameters and call the most specific constructors. I thought I ...
0
votes
3
answers
205
views
My Java-Triangle Code doesn't print the full Triangle
I have to write a code that prints a triangle which the length of the last line is the input number. Also the empty spaces have to be filled with dots.
It has to look like this.
Also, the code has ...
0
votes
2
answers
63
views
Two members, default initialized in Base, possibly non-default initialized in Derived
I have a base class with a default constructor.
class Base
{
public:
Base();
private:
Type1 m_ofType1;
Type2 m_ofType2;
}
Base::Base()
: m_ofType1(defaultExpr1)
, m_ofType2(...
0
votes
1
answer
582
views
Kotlin multiple constructor error: declaration have same java signature
I have two constructors in FirebaseUserAuth class and it is giving an Error: declaration have same java signature. The parameter of constructors are different. Why is it giving same signature error?
...
0
votes
0
answers
153
views
python: multiple constructors(__init__ signatures) in range class, how is it possible? [duplicate]
I'm aware that multiple constructors in python is not possible.
However, I found the range class has two __init__ signatures from the official docs.
class range(stop)
class range(start, stop[, step]...
4
votes
2
answers
7k
views
Spring DI having two constructors at the same time
This is an anti pattern, but I am curious what will actually happen.
If you explicitly define a no-args constructor and a constructor with an autowired parameter, how exactly will spring framework ...
1
vote
4
answers
246
views
Java: Multiple constructors forcing code reuse?
I have a class where one of its members is ArrayList<ArrayList<Double>> elements, and so I have a constructor that takes in that same type and all is good.
public elementArray(ArrayList&...
2
votes
3
answers
7k
views
Kotlin primary constructor calling secondary constructor
Why does this not compile?
class test
{
constructor() {
var a = Date().day
this(a)
}
constructor(a:Int) {
}
}
error is:
Expression 'this' of type 'test' cannot be invoked as a ...
-2
votes
1
answer
472
views
What is the pythonic way to use multiple constructors for a class? [duplicate]
I am writing some genetic algorithms in python. Currently I was looking at a book that has java code, so but eventually I am trying to write my own Adaptive Genetic algorithm to optimize neural ...
0
votes
1
answer
408
views
Scala inheritance of Java constructors
I need to have a Scala class HugeDecimal that inherit from java.math.BigDecimal. It cannot be a trait for internal reasons. The following simple implementation:
class HugeDecimal extends java.math....
1
vote
2
answers
809
views
Two constructors having same no. of parameters but different data types
Here when I run this below code I get called as the output and I was wondering why not called new. Since 1 comes under both short and int range.
public class MyClass {
private int x;
...
0
votes
0
answers
251
views
Castle Windsor: Between multiple constructors why does Castle pick the one with incorrect argument types?
In a scenario where a class has multiple constructors I understand that Castle Windsor has an algorithm used to detect the 'greediest' constructor and pick that one to resolve a component.
But why ...
1
vote
3
answers
1k
views
Is it correct to use multiple constructors this way? [duplicate]
I am not really sure how this works, but if I want to give the option for giving more or less variables to an object of a class, would this work with multiple constructors like this?
Let's say I ...
3
votes
1
answer
191
views
How to correctly configure multiple constructors?
I'm doing an assignment based around inheritance and I have created 2 constructors that are suppose to do different things. One constructor does not have any parameters and should produce a pre-...
1
vote
1
answer
2k
views
How to call a super constructor from another inherited class? [duplicate]
I have been instructed to do the following:
Create a constructor with no arguments in Carnivore that call the super constructor in Animal.
Carnivore is a sub class of Animal which is the super class. ...
0
votes
3
answers
408
views
Constructor chaining with class as parameter
Question about chaining constructor with Class Parameter.
I have a Form with a list box. This form is for debug purpose.
When I instanciate all my object (Class) I want them to write in this list box ...
0
votes
2
answers
4k
views
javascript How to add constructor object with user input
I'm looking for help troubleshooting this code. My assignment is to make a blog which I can make multiple new articles on. I am using an event listener, linked to the submit button. But when I run the ...
-1
votes
1
answer
695
views
Multiple Constructors class JS [duplicate]
I'm from C++, and i try to understand JS OOP. But I have to admit it isn't simple ...
I want to create a "simple" class.
Like this :
class Being {
Being(float A, float B) {...}
Being(string A, ...
2
votes
1
answer
1k
views
Java using default constructor
I have hit a little problem with constructors at my program. It is a simple bank database which stores customer data. I have to implement methods for depositing, withdrawing and transferring cash ...
0
votes
1
answer
111
views
Java to Scala with multiple constructors [duplicate]
I have a Java class that I am trying to rewrite into Scala. It has 3 constructors that need to be available even though I am only using 1.
public class EntityNet extends EntityThrowable {
@...
0
votes
0
answers
84
views
For Python 3.5, can a subclass be constructed from an alternate constructor of its superclass? [duplicate]
This is a corner I have painted myself into a few times. I would have thought given how common alternate constructors are in Python that it would not be unheard of to construct a subclass from an ...
2
votes
1
answer
65
views
Problems parsing in objects from buffered file and sending to the proper constructors
So i am having trouble wrapping my head around an issue, current working on a midi player that reads a file using buffered reader. i am reading the each object from the file as a string into an array ...
0
votes
1
answer
74
views
Is it safe to cascade constructors in Objective C?
I want to do the following:
// I want to do this! :D
- (instancetype) init
{
return [self initWithVal1:[NSDecimalNumber zero] val2:MyEnumDefault];
}
- (instancetype) initWithVal1:(...
4
votes
2
answers
191
views
Inheriting constructors work only partially
I have following class, written so, as to work completely, whatever the typedef is:
class A
{
protected:
typedef uchar mDataType;
std::vector<mDataType> mData;
uint32 mWidth;
...
1
vote
1
answer
183
views
self:: referring to derived class in static methods of a parent class
I liked the idea presented in this answer allowing having something like multiple constructors in PHP. The code I have is similar to:
class A {
protected function __construct(){
// made ...
1
vote
3
answers
79
views
A constructor containing another constructor of the same Class/Object
I am having a class SomeClass with the following member fields and the constructors
private int someInt;
private String someStr;
private String strTwo;
//the contructors
public SomeClass() {}
// ...
0
votes
0
answers
31
views
Trouble printing elements in ArrayList from user input [duplicate]
I am having trouble trying to figure out why my program is not printing the user input (plane ids,capacity). I edited my code so when the user selects print planes print plane info it works fine. ...
0
votes
1
answer
130
views
Construction looping through object creation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CodyGarrettEX3
{
public class Account
{
private long ...
1
vote
3
answers
710
views
using keyword this with multiple constructors in a Class
I don't understand what happens when you create a Rational object with the constructor Rational(). My book says it will create a Rational object whose value is 0 but internally stored as 0/1. How does ...
12
votes
6
answers
878
views
Choosing constructor for a noncopyable object
Assume I have a non-copyable class with multiple constructors with like this
class Foo: boost::noncopyable
{
public:
Foo(std::string s) {...}; // construct one way
Foo(int i) {...};...
0
votes
3
answers
7k
views
Duplicate method Meeting(String) in type Meeting - Error
Hi Guys I'm having error regarding Duplicate Constructors, but according to my Assignment i need a another constructor but different field.
Specifications:
Meeting – Location, Subject, list of ...
3
votes
2
answers
421
views
Can I call a overloaded constructor of the same class in C#?
I know that I can do that with ': this()' but if I do that the overloaded constructor will be excecuted first and I need it to be executed after the the constructor that will call it . . . . Is ...
3
votes
3
answers
2k
views
C# alternate parameterless constructor
Is it possible to define an alternate parameterless constructor for a C# class?
In other words, I have a class Foo. I want to have a default constructer Foo() and another constructor SpecialFoo(). ...
2
votes
2
answers
98
views
How do I convert a string to an new object's name?
I'd like to write a program which creates a set of objects in a loop....
(i.e.)
String newFirm = "empty";
for(int i=0; i<30; i++)
{
newFirm = "firm" + i;
firm newFirm = ...
0
votes
1
answer
148
views
inheritance Problems with undefined types
I want to be able to create a constructor that can call on its types but without any constraints.
public class Box
{
public class Command
{
public string name;
public string ...
3
votes
1
answer
212
views
understanding Scala behaviour in auxiliary constructors with a function as parameter
I have been learning Scala, it has been so good so far, sadly i have found certain behaviour that i don't fully understand. I hope you guys can give me some clues, the problem emerged when i coded ...
1
vote
2
answers
824
views
Unit testing legacy code with multiple constructors but no getter methods
I am trying to unit test (in java) a piece of code which has several constructors and some with logic in them. So apart from setting some fields, the constructors may affect certain static objects ...
11
votes
4
answers
1k
views
How to extend ImageView in an Android-Scala app?
I have tried many solutions found in google by the keywords: multiple constructors, scala, inheritance, subclasses.
None seems to work for this occasion. ImageView has three constructors:
ImageView(...
-2
votes
4
answers
1k
views
I need to create two more constructors, but Java won't let me
OK, I need to create three constructors as part of a project, one default, one general and one copy. I've managed to create a default constructor, but I can't create either the general or copy ...
11
votes
5
answers
21k
views
How to simplify multiple constructors?
I would like to have two constructors for a class, as follows:
public MyClass()
{
// do stuff here
}
public MyClass(int num)
{
MyClass();
// do other stuff here
}
Is the above the ...
3
votes
4
answers
7k
views
How to declare constructors in base classes so that sub-classes can use them without declaring them?
I want a subclass to use its parent's constructors. But it seems I always need to define them again in the subclass in order for that to work, like so:
public SubClass(int x, int y) : base (x, y) {
...
4
votes
3
answers
2k
views
Scala: Generic class with multiple constructors
I'm trying to create a generic class like this:
class A[T](v: Option[T]) {
def this(v: T) = this(Some(v))
def this() = this(None)
def getV = v
}
Then I do some testing:
scala> new A getV
...
8
votes
2
answers
14k
views
How to implement php constructor that can accept different number of parameters?
How to implement php constructor that can accept different number of parameters?
Like
class Person {
function __construct() {
// some fancy implementation
}
}
$a = new Person('...
8
votes
3
answers
2k
views
Few questions about constructors in C#
In C# regarding the inheritance of constructors:
I have read that constructors cannot be inherited.
If the base class contains a constructor, one or more, the derived class have to always call one of ...
5
votes
6
answers
214
views
C++ constructor question
In the C++ programming for the absolute Beginner, 2nd edition book, there was the following statement:
HeapPoint::HeapPoint(int x, int y): thePoint(new Point(x,y)) { }
Is this equal to:
HeapPoint::...
8
votes
2
answers
5k
views
javascript: different constructors for same type of object
is it possible to have more than one constructors for a class in javascript?
i.e. one with zero parameters, one with one, one with two, etc...
if so, how?
thanks!
8
votes
5
answers
3k
views
this() and base() constructors in C#
There seems to be no language syntax for specifying both a this() and a base() constructor. Given the following code:
public class Bar : Foo
{
public Bar()
:base(1)
//:this(0)
{ }
...