Hi Niclas,

> Quite often I come into the situation of the following code in
> ConfigurationComposites;
> 
> @Optional
> Property<String> something();
>
> String something = conf.configuration().something().get();
> if( something == null )
> {
>     something = "some default";
>     conf.configuration().something().set( something );
> }

I wrote exactly the same code at many places in my code.

> And it just struck me; Why is that? Why can't this be handled behind
> the scenes gracefully by Qi4j Runtime?
>
> So,
> 
> @Optional( "some default" )
> Property<String> something();
> 
> which not only makes the implementation code a lot cleaner, but also
> communicate intent a lot better, instead of sticking it into Javadocs.
> I am not entirely sure how the semantics with default settings from
> assembly should be. Possibly the assembly should override the
> programmatic declaration.
> 
> It should work equally well (I seldom have @Optional on those) of
> method parameters.

At first I tried to use the @UseDefaults annotation to see if it could take
parameters, but I feel that @Optional communicate better that it's
optional to set the annoted Property during build (I mean using an
EntityBuilder).

What about non "native" properties like Date/DateTime, enums etc...
Is it possible to write an annotation that can enforce the given value is of
the Property boxed type ?

Best regards

/Paul



_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to