Yannick Le Teigner

Greenhorn
+ Follow
since Aug 13, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Yannick Le Teigner

Thank you all for those helpful information.

Rovas,

I am not using ObjectOutputStream/ObjectInputStream because I want to squeeze the maximum performance possible in my implemantation. Those objects are going to be written on disk, and I believe ObjectOutputStream/ObjectInputStream writes the variable names to the stream, this is something for example that I don't need.


Ernest,

I like this idiom and this is what I will use. It forces me to use reflection, but it is clean.

Tony,

In fact I do not need to access any object's member, I just wanted to force an object to be able to re-construct itself from a ByteBuffer. Calling a constructor with a ByteBuffer as an argument seemed the most logical way, but as I cannot enforce this design I will use Ernest's suggestion.


Thank you again and best regards.
19 years ago
I would even add that for those concerned with the security issues that this causes, they can start the java app with a security manager ( -Djava.security.manager on the CLI). This can prevent access to private/package fields/methods.
19 years ago
Hello,

I am building a small library to persist small java Objects. Objects that wants to be persisted must implement an interface (let's say ByteSerializable).
This interface defines a method (public ByteBuffer save()) that will be called when the object needs to be saved, and as per the API contract, must return a 'serialized' version of this object in a bytebuffer.
Now to restore this object, I would like the interface to define a constructor like (public object_name(ByteBuffer )) that will be called when the object needs to be restored from a ByteBuffer. Unfortunately, as far as I know, one cannot influence a class' constructor definition thanks to interfaces.
A function like (public Object restore(ByteBuffer )) would also work if I could make sure that Object is an instance of the class implementing the interface.
Is there any way to force this requirement through interfaces? Or should I just write in the API contract that a object that wants to be persited must also provide a constructor taking a ByteBuffer as argument. (and hope that the users will not forget this..) ?

Any help will be very much appreciated!
Thanks,
19 years ago