Nice/stdlib/nice/lang prelude.nice,1.40,1.41
Artem Gr Kozarezov <[email protected]>
| Newsgroups | gmane.comp.lang.nice.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/nice/Nice/stdlib/nice/lang
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9419/stdlib/nice/lang
Modified Files:
prelude.nice
Log Message:
maybeNull
Index: prelude.nice
===================================================================
RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/prelude.nice,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** prelude.nice 5 Nov 2004 15:22:05 -0000 1.40
--- prelude.nice 7 Mar 2005 09:49:21 -0000 1.41
***************
*** 38,48 ****
final class Null<+T> extends Maybe<T> = native;
! /**
! Throws java.lang.NullPointerException if the argument is <code>null</code>.
!
! This call presently does no check, assuming that a dereferencing
! is coming next and will detect nullness.
! This should probably be fixed so that the semantics is well defined.
! */
<T> !T notNull(?T value)
{
--- 38,45 ----
final class Null<+T> extends Maybe<T> = native;
! /**
! * Assert that a <code>value</code> it not <code>null</code>.
! * Throws java.lang.AssertionError if assertions are enabled and the argument is <code>null</code>.
! */
<T> !T notNull(?T value)
{
***************
*** 51,54 ****
--- 48,63 ----
}
+ /**
+ * Tell the compiler that the <code>value</code> might be <code>null</code>.<br>
+ * Useful to check if the variable is <code>null</code>
+ * without issuing a compile-time warning: <code>if( maybeNull( var ) == null )</code>.<br>
+ * The need for this method might arise in particular when using
+ * existing Java libraries. Nice often thinks that Java method
+ * would not return a <code>null</code> value, and it is not always practical
+ * to write a retyping for the method.<br>
+ * See also the "Option types" chapter of the Nice manual.
+ */
+ <T> ?T maybeNull(!T value) = value;
+
/****************************************************************
* Primitive types
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click