[concurrency-interest] ReentrantReadWriteLock backport non-matching signature

Rémi Forax forax at univ-mlv.fr
Fri Jul 14 15:49:47 EDT 2006


Dhanji R. Prasanna wrote:

> Somewhat off topic--does anyone know if covariant return types support 
> boxing for primitives?
> For instance can I return Serializable on an overriden int method?

your example is strange, Serializable is not  a subtype of int or even 
Integer.

JLS just allow covariant return type between objects, the idea behind is 
that the generated
bridge method can delegating but is not allowed to perform any processing
(perhaps in order to be suppressed at runtime by an intelligent VM)
so by example, this code doesn't compile :
class A {
  int f() {return 2;}
}
class B extends A {
  double f() { return 3.0; }
}

> (eclipse complains, but I know eclipse has plenty of bugs with its 
> "intelligent" sensing features)

eclipse use a builtin compiler and not javac so the bugs are not the same :)

>
> On 7/11/06, *David Holmes* <dcholmes at optusnet.com.au 
> <mailto:dcholmes at optusnet.com.au>> wrote:
>
>     Holger Hoffstatte writes:
>     > Maybe it was just an oversight. Still, the whole point of having
>     > interfaces is to decouple from the concrete class. I remember
>     when I tried
>     > to make the backport run (at least partly) on native j.u.c. this
>     was one
>     > of the primary showstoppers, at least for me.
>
>     co-variant return types means we can get the best of both worlds.
>     The class
>     can declare that it returns a more specific type that the client
>     may choose
>     to use, if there is something more specific that the client wants
>     to use.
>     But the client is free to declare their variables as the less
>     specific ie
>     interface, type.
>
>     This is no different to doing:
>
>     ReentrantLock l = new ReentrantLock();
>
>     rather than:
>
>     Lock l = new ReentrantLock();
>
>     You get to choose the type of your variables.
>
>     > Regarding the incompatibility it seems Moran has found a good
>     solution by
>     > just referring to the interface in client code. (phew!)
>
>     That's good.
>
>     Cheers,
>     David
>
Rémi Forax



More information about the Concurrency-interest mailing list