Interesting Casting question

  • Thread starter =?ISO-8859-1?Q?Andreas_R=F8sdal?=
  • Start date
?

=?ISO-8859-1?Q?Andreas_R=F8sdal?=

Why do I get a "incompatible types"-compilation error when
casting like this:
opponent = (PlayerInterface)Naming.lookup(url);

The definitions looke like this:
public class Player extends UnicastRemoteObject implements PlayerInterface
public interface PlayerInterface extends Remote

The Player-class implements all functions from the interface...


Thanks,

ANdreas R.
 
W

Wendy S

Andreas Røsdal said:
Why do I get a "incompatible types"-compilation error when
casting like this:
opponent = (PlayerInterface)Naming.lookup(url);

I think the cast is applying only to 'Naming'. Try another set of
parentheses:
opponent = (PlayerInterface)(Naming.lookup(url));

Now you're casting the result of Naming.lookup(url) to type PlayerInterface.
 
?

=?ISO-8859-1?Q?Andreas_R=F8sdal?=

I think the cast is applying only to 'Naming'. Try another set of
parentheses:
opponent = (PlayerInterface)(Naming.lookup(url));

Now you're casting the result of Naming.lookup(url) to type PlayerInterface.

Thanks, I found the error.
The definition of the opponent was declared to be Player, not
PlayerInterface.
 
T

Tony Morris

Andreas Røsdal said:
Why do I get a "incompatible types"-compilation error when
casting like this:
opponent = (PlayerInterface)Naming.lookup(url);

The definitions looke like this:
public class Player extends UnicastRemoteObject implements PlayerInterface
public interface PlayerInterface extends Remote

The Player-class implements all functions from the interface...


Thanks,

ANdreas R.

How is "opponent" declared ?

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top