Problems complying to a Java method signature

64 views
Skip to first unread message

Sebastian Nozzi

unread,
May 26, 2013, 3:12:09 PM5/26/13
to scala...@googlegroups.com
Hi,

I'm in a sort of catch-22 against the Scala compiler. I am overseeing something but can't find the way to satisfy the compiler...

I am trying to compile the basic "Hello World" of the RoboVM project, described here:


But I am using the Scala version found here:


My problem is with the line 37:

override def didFinishLaunching(application: UIApplication, launchOptions: NSDictionary) = {

For the record, NSDictionary is defined (as part of this framework, in Java) like this:

public class NSDictionary<K extends NSObject, V extends NSObject>
    extends NSObject
    implements Map<K, V> { ... }

Now, the different things I tried out and the compiler errors:

1) If I leave NSDictionary like that, the compiler says:
RoboTest.scala:37: error: class NSDictionary takes type parameters

2) If I change it to NSDictionary[NSObject, NSObject], or even NSDictionary[_, _] then:
RoboTest.scala:37: error: method didFinishLaunching overrides nothing.
Note: the super classes of class RoboTest contain the following, non final members named didFinishLaunching:
def didFinishLaunching(x$1: org.robovm.cocoatouch.uikit.UIApplication): Unit
def didFinishLaunching(x$1: org.robovm.cocoatouch.uikit.UIApplication,x$2: org.robovm.cocoatouch.foundation.NSDictionary): Boolean

3) If I remove the "override" and leave it like NSDictionary[NSObject, NSObject], then:
RoboTest.scala:37: error: name clash between defined and inherited member:
method didFinishLaunching:(application: org.robovm.cocoatouch.uikit.UIApplication, launchOptions: org.robovm.cocoatouch.foundation.NSDictionary[org.robovm.cocoatouch.foundation.NSObject, org.robovm.cocoatouch.foundation.NSObject])Boolean and
method didFinishLaunching:(x$1: org.robovm.cocoatouch.uikit.UIApplication, x$2: org.robovm.cocoatouch.foundation.NSDictionary)Boolean in class Adapter have same type after erasure: (application: org.robovm.cocoatouch.uikit.UIApplication, launchOptions: org.robovm.cocoatouch.foundation.NSDictionary)Boolean

How to satisfy the compiler in this case?

What is then the correct method signature for the Scala side, for line 37, given the Java definition?

Thanks in advance for any hints!

Sebastian


Jason Zaugg

unread,
May 26, 2013, 3:49:13 PM5/26/13
to Sebastian Nozzi, scala-user
On Sun, May 26, 2013 at 9:12 PM, Sebastian Nozzi <sebn...@gmail.com> wrote:
I'm in a sort of catch-22 against the Scala compiler.

We call those TupleN-situations around here :)
 
override def didFinishLaunching(application: UIApplication, launchOptions: NSDictionary) = {

For the record, NSDictionary is defined (as part of this framework, in Java) like this:

public class NSDictionary<K extends NSObject, V extends NSObject>
    extends NSObject
    implements Map<K, V> { ... }
 
2) If I change it to NSDictionary[NSObject, NSObject], or even NSDictionary[_, _] then:
RoboTest.scala:37: error: method didFinishLaunching overrides nothing.
Note: the super classes of class RoboTest contain the following, non final members named didFinishLaunching:
def didFinishLaunching(x$1: org.robovm.cocoatouch.uikit.UIApplication): Unit
def didFinishLaunching(x$1: org.robovm.cocoatouch.uikit.UIApplication,x$2: org.robovm.cocoatouch.foundation.NSDictionary): Boolean

This was the closest. Try:

   NSDictionary[_ <: NSObject, _ <: NSObject]

I created a gist [1] with the simplified example I used to try this out.

Note that from Scala 2.11.0-M3 [2], the compiler infers those bounds for you, so you could just write:

  NSDictionary[_, _]

-jason

Sebastian Nozzi

unread,
May 26, 2013, 4:18:18 PM5/26/13
to scala-user
It compiles! Thanks a lot! :-D

(ahh, still so much to learn...)

Interesting the info about 2.11... 

Just for curiosity, why doesn't just NSDictionary[NSObject, NSObject] work in this case?



2013/5/26 Jason Zaugg <jza...@gmail.com>

Jason Zaugg

unread,
May 26, 2013, 4:29:53 PM5/26/13
to sebn...@googlemail.com, scala-user
On Sun, May 26, 2013 at 10:18 PM, Sebastian Nozzi <sebn...@gmail.com> wrote:
It compiles! Thanks a lot! :-D

(ahh, still so much to learn...)

Interesting the info about 2.11... 

Just for curiosity, why doesn't just NSDictionary[NSObject, NSObject] work in this case?
 
M[_ <: A] is means we don't know the type argument, we only know that it has an upper bound of A. It's known as a existential type and its not the same type as M[A]. Parameter types must match exactly to keep things sound.

-jason

Reply all
Reply to author
Forward
0 new messages