null type mismatch with eclipse 4.4rc1 and java 1.8 [message #1378575] |
Sat, 24 May 2014 09:38  |
Eclipse User |
|
|
|
using eclipse 4.4RC1 with "compiler compliance level 1.7", the code below is fine, but with "compiler compliance level 1.8", it doesn't work.
if you use "(E)null" instead of "null" the code work with a warning
import org.eclipse.jdt.annotation.Nullable;
public class Test2<E> {
@Nullable
E test() {
return null;
}
void test2() {
E local = null;
}
}
|
|
|
|
Re: null type mismatch with eclipse 4.4rc1 and java 1.8 [message #1379174 is a reply to message #1379023] |
Sat, 24 May 2014 15:43   |
Eclipse User |
|
|
|
I have read the bugs, but I don't understand why it is related.
I declared the variable @Nullable, so it has to be nullable, indeed (E)null works ok.
the declaration
public class Test2<@Nullable E> {
}
give me an error, maybe I miss something
However, E type can be null or not null at class level, but I think I always can do a local variable null:
@NonNull E test2() {
E local = null;
...
if( local != null )
return E;
....
}
Thomas Schindl wrote on Sat, 24 May 2014 10:11That's to be expected! You need to annotate the generic type
> import org.eclipse.jdt.annotation.Nullable;
>
> public class Test2<@Nullable E> {
> @Nullable
> E test() {
> return null;
> }
>
> void test2() {
> E local = null;
> }
> }
I had the same missunderstanding see
https://bugs.eclipse.org/bugs/show_bug.cgi?id=434374#c8 and
https://bugs.eclipse.org/bugs/show_bug.cgi?id=434374#c11
Tom
On 24.05.14 11:38, Nicola Zanaga wrote:
> import org.eclipse.jdt.annotation.Nullable;
>
> public class Test2<E> {
> @Nullable
> E test() {
> return null;
> }
> void test2() {
> E local = null;
> }
> }
|
|
|
Re: null type mismatch with eclipse 4.4rc1 and java 1.8 [message #1379412 is a reply to message #1379174] |
Sat, 24 May 2014 18:08   |
Eclipse User |
|
|
|
The semantics of null type annotations in relation to type parameters and type variables still needs to be documented. I hope I'll find the time to include the basic explanations into the Luna migration guide.
Basically, all examples you give work as designed, but:
Quote:
the declaration
public class Test2<@Nullable E> {
}
give me an error, maybe I miss something
this works for me. What error are you seeing?
best,
Stephan
|
|
|
|
Powered by
FUDForum. Page generated in 0.03343 seconds