Implementing method problems

51 views
Skip to first unread message

Donald McLean

unread,
Oct 6, 2016, 3:15:13 PM10/6/16
to scala-user
I'm trying to implement an instance of the class org.hibernate.Query, which has two abstract methods "setLong". When I try to implement them, I get a compile error.

Could some kind soul please tell me what the heck is going on and how I might be able to fix it?

Thank you,

Donald

Error:(445, 18) method setLong overrides nothing.
Note: the super classes of class test contain the following, non final members named setLong:
def setLong(x$1: String,x$2: Long): org.hibernate.Query
def setLong(x$1: Int,x$2: Long): org.hibernate.Query
    override def setLong(i: Int, l: Long): org.hibernate.Query = ???
Error:(447, 18) method setLong overrides nothing.
Note: the super classes of class test contain the following, non final members named setLong:
def setLong(x$1: String,x$2: Long): org.hibernate.Query
def setLong(x$1: Int,x$2: Long): org.hibernate.Query
    override def setLong(s: String, l: Long): org.hibernate.Query = ???

abstract class test extends org.hibernate.Query {
override def setLong(i: Int, l: Long): org.hibernate.Query = ???

override def setLong(s: String, l: Long): org.hibernate.Query = ???
}
(the above is exactly what I get when I do "implement methods" in the IDE)

virtualeyes

unread,
Oct 6, 2016, 3:22:36 PM10/6/16
to scala-user
Hibernate's written in Java -- it knows nothing about Scala primitives; try:
override def setLong(i: java.lang.Integer, l: java.lang.Long): org.hibernate.Query

Donald McLean

unread,
Oct 6, 2016, 7:12:53 PM10/6/16
to scala-user
Unfortunately, that's not the answer:

Error:(505, 18) method setLong overrides nothing.
Note: the super classes of class MockHQuery contain the following, non final members named setLong:

def setLong(x$1: String,x$2: Long): org.hibernate.Query
def setLong(x$1: Int,x$2: Long): org.hibernate.Query
    override def setLong(s: java.lang.String, l: java.lang.Long): Query = ???

I also tried creating a Java class that implements two separate methods that bridge to non-overloaded function names:

abstract public class BridgeQuery implements Query {
@Override
public Query setLong(int i, long l) {
return setLongByIndex(i, l);
}

abstract Query setLongByIndex(int i, long l);

@Override
public Query setLong(String s, long l) {
return setLongByName(s, l);
}

abstract Query setLongByName(String s, long l);
}
I've seen this work in cases where the Scala confuses Java types in a way that it's impossible for the Scala compiler to determine which function to override.


--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Family photographs are a critical legacy for
ourselves and our descendants. Protect that
legacy with a digital backup and recovery plan.

Alvaro Carrasco

unread,
Oct 7, 2016, 4:34:04 PM10/7/16
to Donald McLean, scala-user
Seems to work fine for me:

Alvaros-MacBook-Pro:~ alvarocarrasco$ amm
Loading...
Welcome to the Ammonite Repl 0.7.7
(Scala 2.11.8 Java 1.8.0_72)
@ import $ivy.`org.hibernate:hibernate-core:4.3.11.Final`
import $ivy.$
@ abstract class test extends org.hibernate.Query {
    override def setLong(i: Int, l: Long): org.hibernate.Query = ???

    override def setLong(s: String, l: Long): org.hibernate.Query = ???
  }
defined class test
@
Reply all
Reply to author
Forward
0 new messages