Adding the ?. null verification

Etienne via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 18 08:57:39 PDT 2014


On 2014-06-18 11:55 AM, bearophile wrote:
> Etienne:
>
>> writeln(obj.member?.nested?.val);
>
> What about an approach like Scala instead?
>
> Bye,
> bearophile

You mean like this?


http://stackoverflow.com/questions/1163393/best-scala-imitation-of-groovys-safe-dereference-operator

def ?[A](block: => A) =
   try { block } catch {
     case e: NullPointerException if e.getStackTrace()(2).getMethodName 
== "$qmark" => null
     case e => throw e
   }

val a = ?(b.c.d.e)



More information about the Digitalmars-d mailing list