TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Null is your friend, not a mistake

2 点作者 raytracer大约 6 年前

1 comment

adrianmsmith大约 6 年前
Ideally, as the article suggests, you should use a language which supports null and not-null types, with compile errors if you call a method on a type that might be null before checking to make sure it’s not null.<p>However, if you’re stuck with Java, which doesn’t do that, you can annotate your types with @Nonnull and @CheckForNull. (At least) SpotBugs and IntelliJ respect such annotations.<p>I have done this to every parameter type, return type, and instance variable on a 15 KLOC codebase and it’s been a great success.