Skip to content

set-record vs copy-record #44

@Neiko2002

Description

@Neiko2002

Right now a set-record method copies the content of a record but does not change its reference pointer to the copies record. This seems counterintuitive to vanilla java.

Sample13 obj = Records.create(blueprintId);
Bar bar = obj.getBar();
bar.setFraction(0.1f);
// prints -> obj: {bar: {fraction: 0.1}}

Sample13 otherObj = Records.create(blueprintId);
otherObj.setBar(bar);
// prints -> otherObj: {bar: {fraction: 0.1}}

bar.setFraction(0.5f);
// prints -> obj: {bar: {fraction: 0.5}}
// prints -> otherObj: {bar: {fraction: 0.1}}

https://github.com/WhenPerformanceMatters/Records/blob/master/src/test/java/net/wpm/record/samples/RecordsSample_13_NestedRecords.java

It might be better to change the behavior and point the bar-view to the bar-record of the otherObj when using a set-record method. The old behavior should be accessible via a copy-record method e.g. copyBar(bar).

Maybe we should remove the set-record methods and make all views coming from get-record methods or Record.view() immutable to pointer changes. Only views from Record.resuableView() can be reused and they return true for the isReusableView() method, added to every view.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions