All Questions
Tagged with immutability java
19 questions
4
votes
1
answer
127
views
Lift simulator in Java
I implement a working version of the Lift Kata
Can you provide me some tips to improve my code?
I am not very proud of the handleLiftWithOpenDoors method that have ...
3
votes
2
answers
255
views
Immutable employee class
I have created an employee object to be immutable.
...
8
votes
3
answers
2k
views
Stack as a Persistent Data Structure Implementation
After reading some articles about immutability, I found out that there are persistent data structures. In the following, I implemented a stack as a persistent data structure.
What I like about the ...
1
vote
2
answers
2k
views
Creating a Student class for a project
To recover from yesterday's disaster, I re-read the SOLID principles and refactored my code. Hopefully I did a better job than yesterday. I wanted to keep my Student...
1
vote
2
answers
264
views
Creating Immutable Student Object
For a project I'm working on I have the following requirements:
We have two student types: Domestic and International
...
0
votes
1
answer
70
views
Class that holds calculation results and has to be immutable
I'm roughly trying to follow the guidelines in "Effective Java", "Item 15: Minimize mutability", hence the class is not "final" on purpose.
Information is gathered from a number of temperature ...
23
votes
4
answers
28k
views
Simple builder pattern implementation for building immutable objects
This is a builder pattern implementation to build immutable Person objects:
Person class
...
3
votes
5
answers
295
views
An immutable person
I am trying to model person in OOPS using immutability.
I have created an object bond with age as 25. To change the age I have created a new object and returned it.
...
6
votes
4
answers
279
views
Creating SOLID immutable and mutable Location types
I have a Location type:
...
9
votes
4
answers
5k
views
Creating unique registration numbers using object factories
I'm learning about immutability and uniqueness in Java, particularly the use of defensive programming and object factories.
I have been asked to create a class containing an object factory that when ...
1
vote
1
answer
105
views
Removing getters for a custom enum [closed]
Recently, I perform re-factor on one of my frequent used custom enum, by removing its getter.
My rational for doing so it.
The enum's custom fields are immutable
Only use getters when it is ...
4
votes
2
answers
3k
views
Immutable Queue in Java using an Immutable Stack
I am new to this Immutability concept and I have some coding experience in JAVA.
Recently as a part of internship program, they gave me a 5-day task, which was to implement Immutable Queue. After some ...
7
votes
4
answers
10k
views
Should I copy list both in constructor and in getter?
I have a simple immutable class:
...
39
votes
8
answers
5k
views
Immutable objects in Java
I just finished studying immutable objects and their advantages so I thought I'd create one of my own. Here is my employee class that extends a person class. It is not mutable since I have getters to ...
6
votes
3
answers
42k
views
Insert a character into a string
For practicing reasons I would like to write a method which inserts a character into a string.
I would like to know:
What is the best practice concerning placement of a comment within methods? For ...