AbstractStreamEx.nonNull() 的 Eclipse 外部空注释
Eclipse External Null Annotation for AbstractStreamEx.nonNull()
考虑以下示例代码。此代码使用 Eclipse 的 @NonNull
和 @Nullable
注释来检查 null
。不幸的是,Eclipse 在行 map(toNonNull)
.
上标记了一个错误
import java.util.function.Function;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import one.util.streamex.StreamEx;
Function<@NonNull Integer, @Nullable Integer> toNull;
Function<@NonNull Integer, @NonNull Integer> toNonNull;
toNull = value -> value;
toNonNull = value -> value;
StreamEx.
of(1, 2, 3, 4, 5, 6).
map(toNull).
nonNull().
map(toNonNull). // Error is here
count();
错误信息如下:
Null type mismatch (type annotations): required
'Function'
but this expression has type
'Function<@NonNull Integer, @NonNull Integer>'
我想在 StreamEx's nonNull()
(or more precisely AbstractStreamEx 的 nonNull()
) 上创建一个 Eclipse 外部注释,以便 Eclipse 知道流中的值不能为空。
这里是 Eclipse 外部注释的开始。
class one/util/streamex/AbstractStreamEx<TS>
nonNull
()TS;
()???;
我为 ???
添加了什么?
对于 StreamEx 0.6.4 或更新版本,StreamEx 覆盖 nonNull()
以便可以使用以下外部注释:
nonNull
()Lone/util/streamex/StreamEx<TT;>;
()L1one/util/streamex/StreamEx<T1T;>;
对于 StreamEx 0.6.3 或更早版本,一个丑陋的解决方案是更改 Java 代码。这解决了编译器错误。
StreamEx.
of(1, 2, 3, 4, 5, 6).
map(toNull).
nonNull().
map(item -> item != null ? toNonNull.apply(item) : null).
count();
考虑以下示例代码。此代码使用 Eclipse 的 @NonNull
和 @Nullable
注释来检查 null
。不幸的是,Eclipse 在行 map(toNonNull)
.
import java.util.function.Function;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import one.util.streamex.StreamEx;
Function<@NonNull Integer, @Nullable Integer> toNull;
Function<@NonNull Integer, @NonNull Integer> toNonNull;
toNull = value -> value;
toNonNull = value -> value;
StreamEx.
of(1, 2, 3, 4, 5, 6).
map(toNull).
nonNull().
map(toNonNull). // Error is here
count();
错误信息如下:
Null type mismatch (type annotations): required 'Function' but this expression has type 'Function<@NonNull Integer, @NonNull Integer>'
我想在 StreamEx's nonNull()
(or more precisely AbstractStreamEx 的 nonNull()
) 上创建一个 Eclipse 外部注释,以便 Eclipse 知道流中的值不能为空。
这里是 Eclipse 外部注释的开始。
class one/util/streamex/AbstractStreamEx<TS>
nonNull
()TS;
()???;
我为 ???
添加了什么?
对于 StreamEx 0.6.4 或更新版本,StreamEx 覆盖 nonNull()
以便可以使用以下外部注释:
nonNull
()Lone/util/streamex/StreamEx<TT;>;
()L1one/util/streamex/StreamEx<T1T;>;
对于 StreamEx 0.6.3 或更早版本,一个丑陋的解决方案是更改 Java 代码。这解决了编译器错误。
StreamEx.
of(1, 2, 3, 4, 5, 6).
map(toNull).
nonNull().
map(item -> item != null ? toNonNull.apply(item) : null).
count();