I'm trying to migrate an app from NHibernate 1.x to 2.1, and I've noticed something odd: my immutable objects are being deleted in my integration tests.
For example, this test used to pass:
[Test, ExpectedException(typeof(NHibernate.HibernateException))]
public void DeleteExistingInstanceThrows()
{
// Note: NHib transaction is opened/...
a newbie question.
i am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?
please be gentle as it is a newbie question ;-)
thanks & wish you a good day!!
...
Consider the following example.
String str = new String();
str = "Hello";
System.out.println(str); //Prints Hello
str = "Help!";
System.out.println(str); //Prints Help!
Now, in Java, String objects are immutable. Then how come the object 'str' can be assigned value "Help!". Isn't this contradicting the immutability of strings in ...
not only it distress the programmer, it distress the GC (making a new instance every time).
or why aren't they structures?
thanks.
EDIT: do you think that at least it could provide as some method such as ToBold(), that create a new instance, just in bold?
...
How do I make a derived class from Hashtable, objects of which can be added, but cannot be removed or replaced?
What do I have to override and particularly how do I override the [] operator?
...
Hi
In a new Java project I try to apply as much best practices as possible. The one I'm having problems with is immutability. Although I understood the concept and already built some immutable classes I now came to a class where I think it's more appropriate to do it as a mutable class.
The main problem is that I want to hide the mutab...
Let's say I have a C# class:
class Foo
{
private List<Bar> _barList;
List<Bar> GetBarList() { return _barList; }
...
}
A client can call it:
var barList = foo.GetBarList();
barList.Add( ... );
Is there a way to make the Add method fail because only a read-only version of _barList is returned?
...
I am looking for an efficient indexed persistent data structure. I typically work in .NET and am aware of FSharp's Map however that implementation and most others I am aware of only provide a single 'index', the left side of the mapping.
Basically here is the scenario
public class MyObject
public int Id { get; }
public int Gro...
Are all final classes in Java immutable.
String and Integer both are final classes and both are immutable i beleive.
...
Strings are immutable, meaning, once they have been created they cannot be changed.
So, does this mean that it would take more memory if you append things with += than if you created a StringBuffer and appended text to that?
If you use +=, you would create a new 'object' each time that has to be saved in the memory, wouldn't you?
...
In .NET 4 beta 2, there is the new Numerics namespace with struct BigInteger. The documentation states that it is an immutable type, as I would have expected.
But I'm a little confused by the post-increment operator (++). This defintely seems to mutate the value. The following while-loop works:
static BigInteger Factorial(BigInteger ...
Does the Java standard library have any functional data structures, like immutable Sets, Lists, etc., with functional update?
...
I have some classes that represent immutable objects (Quantity, Price, Probability). Is there some way to tell Hibernate that the objects will never change so it can re-use objects rather than creating a new object for every instance of 0 or 1 or Price= $1?
I ended up creating these classes because I discovered that doubles don't do ...
I was looking for a built-in attribute to specify that a type is immutable, and I found only
System.ComponentModel.ImmutableObjectAttribute.
Using Reflector, I checked where it was used, and it seems that the only public class that uses it is System.Drawing.Image... WTF? It could have been used on string, int or any of the primitive ty...
It is safe to assume that working with or passing around an immutable object would always be threadsafe?
...
I have a base Color class that looks something like this. The class is designed to be immutable, so as a result has final modifiers and no setters:
public class Color
{
public static Color BLACK = new Color(0, 0, 0);
public static Color RED = new Color(255, 0, 0);
//...
public static Color WHITE = new Color(255, 255, 255...
I have a class that i use to do downloads. The class is observable and i use it as a swing UI model object too. However it is too slow, both to start (from the http handshaking i presume so not much i can do about it probably) and from synchronized access.
The interface of the class is:
public File getDownloadedFile()
public String get...
I'm using Clojure and I need to run a small simulation. I have a vector of length n (n is usually between 10 and 100) that holds values. On each simulation round (maybe 1000 rounds together), one of the values in the vector is updated randomly. I guess I could do this by using an Java array and calling the aset method, but this would bre...
I'm interested in making an immutable class that has properties that cannot be modified, and a mutable class that derives from it. These objects would be simple data objects representing database records, so they would have only immutable values for the properties.
My goal is to have my data access layer create the mutable versions of ...
This could seem like an obviously hopeless case, but is there a trick to create a cyclic graph of immutable objects in Perl? Something like this:
package Node;
use Moose;
has [qw/parent child/] => (is => 'ro', isa => 'Node');
package main;
my $a = Node->new;
my $b = Node->new(parent => $a);
Now if I wanted $a->child to point to $b, w...