Use an annotation processor

@AutoLiteral
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
class MyFoo {
   public int field1, field2;

}

@Generated(...)
@JsType(IsNative = true, namespace = JsPackage.GLOBAL, name = "Object")
class MyFooLiteral extends MyFoo {
  public MyFooLiteral make() { return new MyFooLiteral(); }
  @JsOverlay
  final public MyFooLiteral field1(int x) { field1 = x; }
  @JsOverlay
  final public MyFooLiteral field2(int x) { field2 = x; }
}


callFunc(MyFooLiteral.make().field1(42).field2(99));


On Tue, Mar 22, 2016 at 9:53 AM, Jens <jens.nehlme...@gmail.com> wrote:
>
>> If your concert is to be able to write one-line initializers, and you are
>> using java8 syntax you also do something like that:
>>
>> public static <T> T apply(T t, Consumer<T> fn) {
>>     fn.accept(t);
>>     return t;
>> }
>>
>> @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
>> class SomeObjectLiteral {
>>     int field1;
>>     String field2;
>> }
>>
>> {
>>     SomeObjectLiteral sol = apply(new SomeObjectLiteral(), o -> { o.field1
>> = 1; o.field2 = "str"; });
>>
>> }
>>
>>
>> Copied from kotlin (although without method extensions and method inline
>> is not the same ;)), this is usable for client and server code when you need
>> to initialize small pojos without fluent api.
>
>
> Looks like a good example how to over-use lambdas. IMHO its just more
> complicated without any added value if its just for initialization.
>
> SomeObjectLiteral sol = apply(new SomeObjectLiteral(), o -> { o.field1 = 1;
> o.field2 = "str"; });
>
> SomeObjectLiteral sol = new SomeObjectLiteral(); sol.field1 = 1; sol.field2
> = "str";
>
>
> Old school is even shorter ;-)
>
>
> -- J.
>
> --
> You received this message because you are subscribed to the Google Groups
> "GWT Contributors" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-web-toolkit-contributors/c007f5d8-48cc-43d5-a813-fa2acaa37337%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAPVRV7etCDXQbeKe9P47qN4N0HLFcqZp03OTReQ%2B0L0nxyD1_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to