where is Nullable in Guice 3.0

1,169 views
Skip to first unread message

leszek

unread,
Feb 12, 2011, 7:29:18 PM2/12/11
to google-guice
Guice 3.0. Where is Nullable annotation.
In Guice 2.0 it was : import com.google.inject.internal.Nullable;
Judging from :
http://code.google.com/p/google-guice/wiki/UseNullable
it should be:
import static javax.annotation.Nullable;
(javax.inject.jar) but in guice-3.0.rc2.zip there is no Nullable
annotaion in this jar

Moandji Ezana

unread,
Feb 12, 2011, 7:41:15 PM2/12/11
to google...@googlegroups.com
From the wiki page: "The Guava: Google Core Libraries for Java and JSR-305 have simple APIs to get a nulls under control." 

So you should get @Nullable from Guava or JSR-305, rather than Guice.

Moandji

Christian Goudreau

unread,
Feb 12, 2011, 7:41:53 PM2/12/11
to google...@googlegroups.com
Well, they removed it. Anyway one should never rely on "internal" type for their own uses I suggest you to move away from internal.Nullable.

Cheers,


--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.




--
Christian Goudreau

Sam Berlin

unread,
Feb 12, 2011, 8:08:10 PM2/12/11
to google...@googlegroups.com

leszek

unread,
Feb 13, 2011, 3:45:40 AM2/13/11
to google-guice
I'm using something like:

@Inject
public RunRaport(@$Nullable @Assisted(InjectParams.FIRST) String
alg,
@Assisted(InjectParams.THIRD) int what,
...........

After moving to Guice 3.0 Nullable annotation cannot be resolved.
Downloading Guava and referencing
javax.annotation.Nullable does not work - probably because guice
source code does not use and recognize it.

All that stuff seems working after replacing Nullable with $Nullable
and manually adding:

import com.google.inject.internal.util.$Nullable;

Seems working but I'm not happy with that. It is final or temporary
solution ?

On 13 Lut, 02:08, Sam Berlin <sber...@gmail.com> wrote:
> See:http://code.google.com/p/google-guice/wiki/Guice30#com.google.inject....

Willi Schönborn

unread,
Feb 13, 2011, 5:31:38 AM2/13/11
to google...@googlegroups.com

On Feb 13, 2011, at 9:45 AM, leszek wrote:

> I'm using something like:
>
> @Inject
> public RunRaport(@$Nullable @Assisted(InjectParams.FIRST) String
> alg,
> @Assisted(InjectParams.THIRD) int what,
> ...........
>
> After moving to Guice 3.0 Nullable annotation cannot be resolved.
> Downloading Guava and referencing
> javax.annotation.Nullable does not work - probably because guice
> source code does not use and recognize it.

Guice should recognize any (!) Nullable annotation, even your own custom ones,
as long as their simple class name is equals to "Nullable".

leszek

unread,
Feb 13, 2011, 6:07:36 AM2/13/11
to google-guice
Yes, ok, it is working. So I've just removed this unhappy $Nullable
from my code and the code is clean. But - by the way - why not add
this Nullable annotation to javax.inject.jar to avoid confusion.

Sam Berlin

unread,
Feb 13, 2011, 10:56:21 AM2/13/11
to google...@googlegroups.com
The wiki link says, "Many things inside com.google.inject.internal changed and/or moved. This is especially true for repackaged Guava (formerly Google Collections), cglib, and asm classes. All these classes are now hidden from IDE auto-import suggestions and are in new locations. You will have to update your code if you relied on any of these classes."  (bold added)

In short: c.g.inject.internal was never meant to be used by users and is now expressly hidden from people using it.

For what to use, see http://code.google.com/p/google-guice/wiki/UseNullable.  It basically says: Using any other annotation whose name is @Nullable will work.  Just make sure annotation is retained at runtime & is on your classpath.

sam
Reply all
Reply to author
Forward
0 new messages