fmgasparino / google-gin

Automatically exported from code.google.com/p/google-gin
Apache License 2.0
0 stars 0 forks source link

Support @Nullable #41

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This should work:

class Foo {
  @Inject Foo(@Nullable @Named("unbound") String s, @Nullable Unimplemented
unimpl);

  interface Unimplemented {}
}

null should be passed for both constructor parameters.

Actually, the unimplemented interface part may be impossible due to the
GWT.create fallback. But we should support nullable injection when possible.

Original issue reported on code.google.com by bstoler+code@google.com on 31 May 2009 at 10:55

GoogleCodeExporter commented 9 years ago
I'm assuming that since this issue is still open that it hasn't been fixed yet?

Original comment by Bitmei...@gmail.com on 13 Nov 2009 at 4:05

GoogleCodeExporter commented 9 years ago
I think you're right. I believe Brian is very busy these days so maybe someone 
else
(like me?) will have to look into this. Do you have an immediate need for this 
feature?

Original comment by aragos on 13 Nov 2009 at 5:04

GoogleCodeExporter commented 9 years ago
I could have used it today, but I've worked around it by providing a 'nullop' 
implementation by default. It would 
simplify configuration for people using the library if it was unnecessary, but 
it's not critical.

Original comment by Bitmei...@gmail.com on 13 Nov 2009 at 5:51

GoogleCodeExporter commented 9 years ago
I could have used @Nullable support! I have a UI toolkit that can be 
instantiated both on client and server side. The UI components only support 
reporting on the server side. Every UI component has a corresponding reporter 
instance (with a custom annotation to make the binding possible).

Now I will have to bind a Null implementation for every possible UI(annotation) 
class that I have :-(

Why not skip the GWT.create when a setter or constructor injection is marked as 
Nullable ?

Original comment by david.nouls on 6 Jul 2011 at 2:34

GoogleCodeExporter commented 9 years ago
Is GIN still being maintained ? Or should I look to alternatives ? This should 
really become part of GWT!

Original comment by david.nouls on 12 Jun 2012 at 9:10

GoogleCodeExporter commented 9 years ago
There is a misunderstanding on the issue mostly due to description.

Adding @Nullable will not let you slip away with something that is not bound.  
It will just let the value to be bound to "null":
 https://code.google.com/p/google-guice/wiki/UseNullable

What most people really need is @Inject(optional=true) which is already 
implemented in GIN:
  https://code.google.com/p/google-guice/wiki/Injections#Optional_Injections

On the @Nullable part;
GIN doesn't even do null checks on injection (IIRC). If it were doing, then 
@Nullable support would have helped to disable the check on some cases. So the 
real use case for @Nullable is actually a minor issue for GIN.

Original comment by gok...@google.com on 16 Apr 2013 at 1:00

GoogleCodeExporter commented 9 years ago
There is a caveat however in the current GIN implementation as Gin tries to 
create by calling GWT.create() instead of failing for @Optional.

See http://code.google.com/p/google-gin/issues/detail?id=70

Original comment by robert.h...@gmail.com on 12 Oct 2013 at 3:34