Quantcast

Implement a raw type

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Implement a raw type

Heiko Seeberger-4
Hi,

Is it possible to extend a Java class that implements a raw type, e.g.

public abstract class JavaThing implements java.util.Comparator {
}

How could compare be implemented in a Scala class extending this:

class ScalaThing extends JavaThing {
  override def compare ???
}

Thank you,

Heiko Seeberger

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implement a raw type

Josh Suereth
override def compare(o : AnyRef, o2 : AnyRef) : Int = 0 // All things being equal ;)

- Josh

On Sat, Jun 12, 2010 at 9:32 AM, Heiko Seeberger <[hidden email]> wrote:
Hi,

Is it possible to extend a Java class that implements a raw type, e.g.

public abstract class JavaThing implements java.util.Comparator {
}

How could compare be implemented in a Scala class extending this:

class ScalaThing extends JavaThing {
  override def compare ???
}

Thank you,

Heiko Seeberger

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implement a raw type

Michael Dürig
In reply to this post by Heiko Seeberger-4
Heiko Seeberger <heiko.seeberger@...> writes:


>
> Is it possible to extend a Java class that implements a raw type, e.g.
>
>
> public abstract class JavaThing implements java.util.Comparator {
> }
>
> How could compare be implemented in a Scala class extending this:
>

Heiko,

Unfortunately in many cases there seems to be no way to implement such classes.
There is a workaround for java.util.Iterator where the generic type only appears
in return values [1]. If the generic type occurs in method parameter there seems
to be no possibility. Some hacks I tried [2] resulted in a NPE in scalac. On the
corresponding ticket [3] Adrian explains why this workaround doesn't work at all.

Michael

[1] http://michid.wordpress.com/2009/06/24/puzzle-implement-this-solution/
[2]
http://michid.wordpress.com/2009/08/30/implementing-java-interfaces-and-generics/
[3] http://lampsvn.epfl.ch/trac/scala/ticket/2091

Loading...