|
|
Re: Eclipse Nullness warning (after Java8) [message #1385764 is a reply to message #1385763] |
Wed, 11 June 2014 06:13 |
Kivanc Muslu Messages: 153 Registered: November 2010 |
Senior Member |
|
|
To my best knowledge, Java8 brought "type" qualifiers, which changed the location (and meaning) of some annotations.
Java7:
@NonNull String [] temp; // temp array cannot be null, we don't know anything about its contents.
Note that with Java7, there was no way to describe/check the nullness of the elements of an array, so the annotation way at the beginning.
Java8:
@NonNull String [] temp; // temp can be null, however if it is not null, its elements cannot be null.
Notice the location of the annotation. It comes before the type "String" so it qualifies String rather than the array. String in this instance represents the elements of the array.
String @NonNull [] temp; // temp cannot be null, we don't know anything about its elements (same as Java7)
Again, notice the place of the annotation. It comes before the array declaration ([]) hence qualifies it.
@NonNull String @NonNull [] temp; // temp cannot be null and its elements cannot be null, too.
I am pretty confident, but I might be missing something, please let me know if this is the case.
Thanks,
|
|
|
Re: Eclipse Nullness warning (after Java8) [message #1385769 is a reply to message #1385764] |
Wed, 11 June 2014 06:57 |
Ed Merks Messages: 33252 Registered: July 2009 |
Senior Member |
|
|
Kivanc,
Okay, it was a dumb question of mine then. No doubt a highly qualified
JDT expert will take note...
On 11/06/2014 8:13 AM, Kivanc Muslu wrote:
> To my best knowledge, Java8 brought "type" qualifiers, which changed
> the location (and meaning) of some annotations.
>
> Java7:
>
> @NonNull String [] temp; // temp array cannot be null, we don't know
> anything about its contents.
>
> Note that with Java7, there was no way to describe/check the nullness
> of the elements of an array, so the annotation way at the beginning.
>
> Java8:
>
> @NonNull String [] temp; // temp can be null, however if it is not
> null, its elements cannot be null.
>
> Notice the location of the annotation. It comes before the type
> "String" so it qualifies String rather than the array. String in this
> instance represents the elements of the array.
>
>
> String @NonNull [] temp; // temp cannot be null, we don't know
> anything about its elements (same as Java7)
>
> Again, notice the place of the annotation. It comes before the array
> declaration ([]) hence qualifies it.
>
>
> @NonNull String @NonNull [] temp; // temp cannot be null and its
> elements cannot be null, too.
>
>
> I am pretty confident, but I might be missing something, please let me
> know if this is the case.
> Thanks,
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.03273 seconds