--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/
To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-lombo...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-lombok?hl=en
In my particular case, I don't actually want to do any more than copy the fields. If you did, could you have a parameter to the annotation like this?
@Data@CopyConstructor(after="postCopy")public class MyObject{
� �private int field1;
� �private void postCopy()� �{� � � field1 = 23;� �}
}
Obviously this creates nasty issues like what to do if the method doesn't exist? (Error at compile time)The other option I see (again, I'm not sure if this is possible?) is to have a separate annotation like @AfterCopyConstructor
@Data@CopyConstructorpublic class MyObject{
� �private int field1;
� �@AfterCopyConstructor� �private void postCopy()� �{� � � field1 = 23;� �}}
In this case, what happens if @AfterCopyConstructor is defined on a method but�@CopyConstructor is not defined? (Fail to create the constructor silently?)
On 24 April 2012 12:31, Reinier Zwitserloot <rei...@zwitserloot.com> wrote:
Yeah, the 'is this actually common boilerplate' issue stuck us too. Also, usually a copy constructor does a little more than 'just' copy fields, so how do we let you add some code? That's harder than it looks, at least if we want to do it in a way that makes it easy to understand and does not require you to dig through a lot of documentation to figure out how it works (i.e. no 'magic methods' which are called at the end).
�--Reinier Zwitserloot
On Tue, Apr 24, 2012 at 12:14, Matthew Jaggard <mat...@jaggard.org.uk> wrote:
This page lists quite a lot of problems with clone()
On 24 April 2012 11:37, Tumi <elbailed...@gmail.com> wrote:
Yes, but the native Object.clone implementation can be 800% or 1000%
slower than this way...
Regards
On Apr 24, 12:54�am, Kevin Ludwig <kevin.lud...@gmail.com> wrote:
> maybe I'm missing something but can't you just implement cloneable? Doesn't
> that automatically provide a clone() method that does shallow copies?
>
--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/
To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-lombo...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-lombok?hl=en
--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/
�
To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-lombo...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-lombok?hl=en
--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/
�
To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-lombo...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-lombok?hl=en
--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/
�
I like to use final fields a lot, so I having a postCopy method is no solution is I would like to clone/modify the contents of the fields in the constructor.
On 24-4-2012 14:06, Matthew Jaggard wrote:
In my particular case, I don't actually want to do any more than copy the fields. If you did, could you have a parameter to the annotation like this?
@Data@CopyConstructor(after="postCopy")public class MyObject{
private int field1;
private void postCopy(){field1 = 23;}}
Obviously this creates nasty issues like what to do if the method doesn't exist? (Error at compile time)The other option I see (again, I'm not sure if this is possible?) is to have a separate annotation like @AfterCopyConstructor
@Data@CopyConstructorpublic class MyObject{
private int field1;
@AfterCopyConstructorprivate void postCopy(){field1 = 23;}}
In this case, what happens if @AfterCopyConstructor is defined on a method but @CopyConstructor is not defined? (Fail to create the constructor silently?)
On 24 April 2012 12:31, Reinier Zwitserloot <rei...@zwitserloot.com> wrote:
Yeah, the 'is this actually common boilerplate' issue stuck us too. Also, usually a copy constructor does a little more than 'just' copy fields, so how do we let you add some code? That's harder than it looks, at least if we want to do it in a way that makes it easy to understand and does not require you to dig through a lot of documentation to figure out how it works (i.e. no 'magic methods' which are called at the end).
--Reinier Zwitserloot
On Tue, Apr 24, 2012 at 12:14, Matthew Jaggard <mat...@jaggard.org.uk> wrote:
This page lists quite a lot of problems with clone()
Is anyone still interested in lombok annotations for this? I've written a javac handler that does some of the things described here and would be happy to contribute that and more. However most of my use cases center around interfaces, so I'm primarily interested in generating conversion constructors that assign fields based on calling getters in an implemented interface or superclass.I still have plenty of work to do, but I have implemented the following so far:1. Copying a basic data contract. If two classes implement the same interface and have fields defined such that an @Data annotation generates implementations of the interface, annotating the classes with @CopyConstructor(TheSharedInterface.class) will generate a conversion constructor with an argument of TheSharedInterface. Some customization would be useful here.2. Deep copying of any class whose members all have a deep copy constructor. Whether to try deep or shallow copying is a configuration option. The trouble with deep copying is of course all of the iterables.3. Deciding when to call super and throwing errors if we can't handle anything super likely didn't handle for us.4. Determining type parameters for generics (including for deep copying and when inheritance and generics are involved).The parts I have not yet implemented (but plan to) include:5. Handle iterables. If the result of a getter is an iterable, the field type might hint at which iterable to use (i.e. List<T> field1 or LinkedList<T> field2). If no implementation class is specified, I will probably end up picking a default per collection type.6. Enable constructor extensibility. I have currently defined an @CopyConstructor annotation at the class level, with an optional class argument telling it what type to copy from. I like the idea of having a class-level annotation, since requiring a constructor would mean requiring unnecessary boilerplate. Perhaps I could change the annotation to be definable at the class or constructor level: if it's at the class level, generate the constructor; if it's on a constructor, inject the generated code into the start of the constructor.I've toyed with generating multiple constructors, compositing constructors, and static factory methods, but I didn't like where I got with any of that. (Example: constructors on a class are obvious, but how do you know a static method is a factory method if it's already been compiled and your annotation has a source retention policy? That makes it nigh impossible to do deep copying.)If there is any interest in including something like this in lombok, I would be happy to share it and keep plugging away on it. Of course the biggest thing missing, by far, is the entire Eclipse implementation, but there are some other features that might be desirable to a broader audience, such as support for fluent getters or direct field access.Anyway, it's a start. Thoughts?
I think its cool but I worry that it becomes a feature that sees very little use and becomes a pain to maintain. There is so much that can be configured about this sort of thing, so do we make it as simple as possible and simply resort to: "Well, if this simplest case does not work for you, then don't use lombok for it and write it out longhand", or make it configurable (which makes the feature much more complicated).
I see that configuring such an annotation can get pretty complex, but in my opinion, Lombok having a basic @CopyConstructor is still better than having no such functionality.