How can I accept an argument list in a constructor and add it to a collection in Java?

I’m trying to make a constructor that would accept any number of variables of class “Item” as a variable argument list and add them to appropriate collection. What would be the best way to …

How to create objects for parameterized constructors in Java, when we have two classes with the same attributes?

I have class Student, that has first name, last name and age, and a method to print the name and the age of the student. public class Student { private String firstName; private String …

Java Problem: Calculations in one subclass’ constructor affecting fields of another subclass’ instance

I have two abstract classes i.e. Medicine and Prescription. All code can be found at https://codeshare.io/aVAdr3 These two classes have subclasses, the class hierarchy diagram is as follows: and… …

Why any initialization or even print inside the constructor with @Tolerate lombok cannot be reached?

what is the problem with the constructor with @Tolerate of lombok, and why it cannot be reached? and how can I fix it? I wanna initialize a map by setting some default keys and values inside the …

super.a = b instead of super(b)

I’m learning the super keyword and accidentally get this, here’s an example : public class A { double a; public A (double a) { this.a = a; } } public class B …

Spring boot error in Application.java package

hello I just created a project in spring boot initializer but when I import the project in sts I have a set of errors that I do not understand package com.example.filter.influenceur.influenceur; …

multiple constructors for final fields in java

I have some final fields in the class like class A { private final boolean a; private final boolean b; public A(boolean a){ this.a = a; } public A(boolean a, boolean b){ this.a = a; …