Closed GoogleCodeExporter closed 9 years ago
All you need is
Preconditions.checkArgument(!s.isEmpty());
someStr = s;
Original comment by kevinb@google.com
on 4 Feb 2011 at 11:51
Using
Preconditions.checkArgument(!s.isEmpty());
Will throw a NPE if s is null, the goal of a checkNotNullOrEmpty is to simplify
a very common check.
Preconditions.checkNotNull(arg) is a shorthand for
Preconditions.checkArgument(arg != null)
Preconditions.checkNotNullOrEmpty(arg) would be a shorthand for
Preconditions.checkArgument(!Strings.isNullOrEmpty(arg))
Original comment by david.morand
on 20 Aug 2014 at 8:15
> Preconditions.checkNotNull(arg) is a shorthand for
Preconditions.checkArgument(arg != null)
No, it's not. The former throws an NPE. You may like it or not, but the Guava
(and JDK) guys fell this decision a long time ago. Therefore
checkArgument(!s.isEmpty()) does exactly the right thing.
For an endless discussion, see http://stackoverflow.com/q/3881/581205
Original comment by Maaarti...@gmail.com
on 21 Aug 2014 at 1:51
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:15
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:09
Original issue reported on code.google.com by
kua...@gmail.com
on 4 Feb 2011 at 3:16