cast and assert
Roman Bednarek <[email protected]> Thu, 25 Mar 2004 09:17:09 +0100 (CET)
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
Hi. I am a newcomer to Nice and I am trying some of its features. I have read an wiki page about cast http://nice.sourceforge.net/cgi-bin/twiki/view/Dev/NiceCasts and have some comments. There are two cases for cast usage: 1) you do not know if the cast is valid that situation is clear you have to check with instanceof: A a=new B(); if(a instanceof B) println(a.b); instead of A a=new B(); printlln(cast(a).b)); 2) you are sure that the cast is valid ( from some other logic) in that case one can use assert in the same way like if statemant before: A a=new B(); assert a instanceof B; println(a.b); // not compiling now with nice 0.9.7 instead of using cast. One could also use requires for that purpose. In that way you can avoid using explicit cast almost everywhere. Does that make any sense? Roman Bednarek ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click