- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
implementing java interfaces
Mon, 2009-02-09, 02:05
Hi, me <- scala newbie, java 12 years
am trying to implement a simple java interface in scala:
interface Listener
{
public void message (Map map, String msg);
}
in Scala, I tried the following:
class Foo extends Listener
{
def message (map :Map[Any,Any], msg :String) :Unit = println ("test")
}
The eclipse plugin context help says:
"class Foo needs to be abstract, since method message in Trait Listener of type
(java.util.Map,java.util.String) Unit is undefined.
Any ideas???
David
Mon, 2009-02-09, 02:37
#2
Re: implementing java interfaces
This worked:
class SListener extends Listener
{
def message (header :java.util.Map[_,_], message :java.lang.String) :Unit =
{
println (message)
}
}
NOTE: I had to type the Map and String too.
Many thanks
Dave
Mon, 2009-02-09, 02:47
#3
Re: implementing java interfaces
This worked:
class SListener extends Listener
{
def message (header :java.util.Map[_,_], message :java.lang.String) :Unit =
{
println (message)
}
}
NOTE: I had to type the Map and String too.
Many thanks
Dave
Mon, 2009-02-09, 03:07
#4
Re: implementing java interfaces
Out of interest:
is java: Map <?, ?>
similar to Scala:
Map [_ ,_]
Mon, 2009-02-09, 03:47
#5
Re: Re: implementing java interfaces
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Yes, the topic you want to read up on is called Existential Types.
It's also similar to Map[T forSome { type T }, U forSome { type U }]
David Moshal wrote:
> Out of interest:
>
> is java: Map <?, ?>
>
> similar to Scala:
>
> Map [_ ,_]
>
>
>
>
>
- --
Tony Morris
http://tmorris.net/
************************************
* Anteromedial Osseous Impingement *
************************************
http://www.ajronline.org/cgi/content/full/178/3/601
"can result in chronic ankle pain, especially in athletes and the
younger population (15-40 years old)"
http://radiographics.rsnajnls.org/cgi/content/figsonly/22/6/1457
"Soft-tissue and osseous impingement syndromes of the ankle can be an
important cause of chronic pain, particularly in the professional
athlete."
1. Take any person with soft tissue and osseous joint impingement from
trauma
2. Surgically tighten the joint ligaments particularly those in the
area of impingement.
3. When the patient complains of incredible and permanent pain, shrug
your shoulders.
Outcome
You'll find the patient at the mental hospital bordering psychosis.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFJj5eSmnpgrYe6r60RAviQAJ4yQ2ANJPDGWYWq2U8TsENDfrudyACgtsly
PKr8Bgmx9tqYV2dpr/6t6wY=
=KIMY
-----END PGP SIGNATURE-----
Mon, 2009-02-09, 10:17
#6
Re: Re: implementing java interfaces
Better to remove the raw type from the original code.
2009/2/9 Tony Morris <tmorris@tmorris.net>
2009/2/9 Tony Morris <tmorris@tmorris.net>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Yes, the topic you want to read up on is called Existential Types.
It's also similar to Map[T forSome { type T }, U forSome { type U }]
David Moshal wrote:
> Out of interest:
>
> is java: Map <?, ?>
>
> similar to Scala:
>
> Map [_ ,_]
>
>
>
>
>
- --
Tony Morris
http://tmorris.net/
************************************
* Anteromedial Osseous Impingement *
************************************
http://www.ajronline.org/cgi/content/full/178/3/601
"can result in chronic ankle pain, especially in athletes and the
younger population (15-40 years old)"
http://radiographics.rsnajnls.org/cgi/content/figsonly/22/6/1457
"Soft-tissue and osseous impingement syndromes of the ankle can be an
important cause of chronic pain, particularly in the professional
athlete."
1. Take any person with soft tissue and osseous joint impingement from
trauma
2. Surgically tighten the joint ligaments particularly those in the
area of impingement.
3. When the patient complains of incredible and permanent pain, shrug
your shoulders.
Outcome
You'll find the patient at the mental hospital bordering psychosis.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFJj5eSmnpgrYe6r60RAviQAJ4yQ2ANJPDGWYWq2U8TsENDfrudyACgtsly
PKr8Bgmx9tqYV2dpr/6t6wY=
=KIMY
-----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
In Scala (or Java either), Map[Any, Any] is not equivalent to Map.
Since Map takes two type variables, Map[_, _] is equivalent to just Map.
David Moshal wrote:
> Hi, me <- scala newbie, java 12 years
>
> am trying to implement a simple java interface in scala:
>
> interface Listener { public void message (Map map, String msg); }
>
>
> in Scala, I tried the following:
>
> class Foo extends Listener { def message (map :Map[Any,Any], msg
> :String) :Unit = println ("test") }
>
>
> The eclipse plugin context help says: "class Foo needs to be
> abstract, since method message in Trait Listener of type
> (java.util.Map,java.util.String) Unit is undefined.
>
> Any ideas???
>
> David
>
>
>
- --
Tony Morris
http://tmorris.net/
************************************
* Anteromedial Osseous Impingement *
************************************
http://www.ajronline.org/cgi/content/full/178/3/601
"can result in chronic ankle pain, especially in athletes and the
younger population (15-40 years old)"
http://radiographics.rsnajnls.org/cgi/content/figsonly/22/6/1457
"Soft-tissue and osseous impingement syndromes of the ankle can be an
important cause of chronic pain, particularly in the professional
athlete."
1. Take any person with soft tissue and osseous joint impingement from
trauma
2. Surgically tighten the joint ligaments particularly those in the
area of impingement.
3. When the patient complains of incredible and permanent pain, shrug
your shoulders.
Outcome
You'll find the patient at the mental hospital bordering psychosis.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFJj4MDmnpgrYe6r60RAk4dAJ9W75C/ObY8LtBTOGgmgMeByBC2SwCffdCu
HrarcDJQxaYFclFiTM+oA+k=
=gzRy
-----END PGP SIGNATURE-----