Overriding a Java Abstract method - overrides nothing

430 views
Skip to first unread message

David

unread,
Nov 21, 2014, 4:16:16 PM11/21/14
to scala...@googlegroups.com
Java Code:

1. public abstract class MyAbstractClass<T>{
2.    protected abstract T execute(Job job) throws Exception;
3. }


Scala Code:

I copy line 2 in the Java code and paste it into MyConcreteClass and Intellij automatically generates lines 3,4,5 and 6.

1. class MyConcreteClass extends MyAbstractClass[String]{
2.  
3.  @throws(classOf[Exception])
4.  override protected def execute(job: Job[_ <: Serializable]): String = {
5.    "test"
6.  }
7.
8. }



However, the compiler still complains that 
Method 'execute' overrides nothing.

Can someone please help me to figure out how to override the java method?

Thanks

David


Clint Gilbert

unread,
Nov 21, 2014, 4:48:21 PM11/21/14
to scala...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Some more code would help. Does the Job class have type params?

On 11/21/2014 04:16 PM, David wrote:
> Java Code:
>
> | 1.publicabstractclassMyAbstractClass<T>{ 2. protectedabstractT
> execute(Jobjob)throwsException; 3.} |
>
>
> Scala Code:
>
> I copy line 2 in the Java code and paste it into MyConcreteClass
> and Intellij automatically generates lines 3,4,5 and 6.
>
> | 1.classMyConcreteClassextendsMyAbstractClass[String]{ 2. 3.
> @throws(classOf[Exception])
>
> 4. override protected def execute(job: Job[_ <: Serializable]):
> String = { 5. "test" 6. }
>
> 7. 8.} |
>
>
> However, the compiler still complains that Method 'execute'
> overrides nothing.
>
> Can someone please help me to figure out how to override the java
> method?
>
> Thanks
>
> David
>
>
> -- 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+...@googlegroups.com
> <mailto:scala-user+...@googlegroups.com>. For more options,
> visit https://groups.google.com/d/optout.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iEYEARECAAYFAlRvsxsACgkQ0GFaTS4nYxuvFQCfUYgYWGobMBkJMAIOJNLqJFRG
Au0AnA8IajyE5hW6zpRtcmO+jBZnxJ9R
=zeBE
-----END PGP SIGNATURE-----

David

unread,
Nov 21, 2014, 4:52:13 PM11/21/14
to scala...@googlegroups.com
Sorry, here is the code for Job:

public class Job<T extends Serializable> implements BreachTask {
...
}

and

public interface BreachTask extends Serializable {
}

Clint Gilbert

unread,
Nov 21, 2014, 4:54:08 PM11/21/14
to scala...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Aha, your Java code omits the type param completely. Try this:

override protected def execute(job: Job[_]): String



On 11/21/2014 04:52 PM, David wrote:
> |
>
> override protected def execute(job: Job[_ <: Serializable]): String
> = {
>
> |
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iEYEARECAAYFAlRvtGgACgkQ0GFaTS4nYxsdNwCdGQrvhAxGcJ5OOAgOHu1gJdzP
ExAAn3s2LGHLhNsWtQ8y9IDtzUyLKHnE
=K16z
-----END PGP SIGNATURE-----

David

unread,
Nov 21, 2014, 5:26:14 PM11/21/14
to scala...@googlegroups.com
Thanks for the replies Clint, but it basically gives the same error:

(Note that com.amp.util.Job does not match
com.amp.util.Job[_].  To implement a raw type, use
com.amp.util.Job[_].

Clint Gilbert

unread,
Nov 21, 2014, 5:31:28 PM11/21/14
to scala...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You should post a minimal self-contained example.

On 11/21/2014 05:26 PM, David wrote:
> Thanks for the replies Clint, but it basically gives the same
> error:
>
> (Note that com.amp.util.Job does not match com.amp.util.Job[_]. To
> implement a raw type, use com.amp.util.Job[_].
>
> On Friday, November 21, 2014 4:54:08 PM UTC-5, Clint Gilbert
> wrote:
>
> Aha, your Java code omits the type param completely. Try this:
>
> override protected def execute(job: Job[_]): String
>
>
>
> On 11/21/2014 04:52 PM, David wrote:
>> |
>
>> override protected def execute(job: Job[_ <: Serializable]):
>> String = {
>
>> |
>
> -- 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+...@googlegroups.com
> <mailto:scala-user+...@googlegroups.com>. For more options,
> visit https://groups.google.com/d/optout.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iEYEARECAAYFAlRvvToACgkQ0GFaTS4nYxs5oACgjCamNgTTxHNPh6t3Wth2O24l
kqMAniIv4gZgG3EX1AGnOOrO2j3WbxEo
=1CQK
-----END PGP SIGNATURE-----

David

unread,
Nov 21, 2014, 5:53:44 PM11/21/14
to scala...@googlegroups.com

Hi Clint, I've attached a very small jar file containing all the source files.

A compile gives the following error:


On Friday, November 21, 2014 5:31:28 PM UTC-5, Clint Gilbert wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You should post a minimal self-contained example.

On 11/21/2014 05:26 PM, David wrote:
> Thanks for the replies Clint, but it basically gives the same
> error:
>
> (Note that com.amp.util.Job does not match com.amp.util.Job[_].  To
> implement a raw type, use com.amp.util.Job[_].
>
> On Friday, November 21, 2014 4:54:08 PM UTC-5, Clint Gilbert
> wrote:
>
> Aha, your Java code omits the type param completely.  Try this:
>
> override protected def execute(job: Job[_]): String
>
>
>
> On 11/21/2014 04:52 PM, David wrote:
>> |
>
>> override protected def execute(job: Job[_ <: Serializable]):
>> String = {
>
>> |
>
> -- 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+...@googlegroups.com
> <mailto:scala-user+unsub...@googlegroups.com>. For more options,
overrides_nothing.jar

Jason Zaugg

unread,
Nov 21, 2014, 8:17:39 PM11/21/14
to David, scala-user
On Sat, Nov 22, 2014 at 8:53 AM, David <david...@gmail.com> wrote:

Hi Clint, I've attached a very small jar file containing all the source files.

A compile gives the following error:

Hi David,

You weere on the right track but were tripped up be a subtle problem: in the signature of MyScalaConcreteClass#execute you bounded the existential with scala.Serializable, rather than java.io.Serializable

I was able to compile this:

class MyScalaConcreteClass extends MyAbstractClass[String]{

  @throws(classOf[Exception])
  override protected def execute (job: Job[_ <: java.io.Serializable]):String = {
    "test"
  }

}

In Scala compilation units, imports of java.lang_, scala._, scala.Predef._ are implied.


-jason


Som Snytt

unread,
Nov 21, 2014, 8:35:21 PM11/21/14
to Jason Zaugg, David, scala-user
Who says the puzzlers are dead?

Long live the puzzlers.

Retronym should present on Scalawags, the way Will Shortz used to appear on NPR on Sunday mornings.  Or does he still do that?

This is just to appreciate the coverage Retronym has given to scala-user problems.  It's kind of a relief when it's our fault and not scalac's.


--
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+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages