java - Checked Exception Variance -


java supports checked exceptions, invariant default @ declaration site. scala allows variance annotations using +t , -t, not have checked exceptions. designing / implementing language supposed support both, wondering how variance works checked exceptions.

example:

interface function[-p1, +r, e] {     public r apply(p1 par1) throws e } 

what kind of variance annotation should e have, or invariant? , further, should generate error if has opposite variance annotation, similar how in scala error if use covariant type argument function parameter type?

things come all time in language design, , there issues of soundness etc., take time think these issues in other aspects of language!

but, anyway, it's means. let's suppose have

interface iofunction[-p1, +r, e <: ioexception] extends function[p1,r,e] 

and have method

public r doio[p1, r](f: iofunction[p1, r, ioexception]) ... 

what if user has hands on function throws myioexception <: ioexception? should able use it?

if yes, that's covariance about. if no, has ioexception or nothing, use invariance.

you can use same reasoning exceptions normal return value. are return value of sorts, not normal one.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -