RandomGuy123456
RandomGuy123456

Reputation: 27

Scala trouble accessing Java methods

So, I have something written in Java, and I want to extend it in Scala... The issue I'm running into is that Scala isn't seeing methods I need.

Here is how it's set up: Player extends Mob, and Mob extends Entity.

I need to access a method in Player that isn't defined in Mob or Entity, but Scala doesn't think it exists even though Java does.

It can see methods defined by Mob and Entity just fine. Also, all the methods I'm talking about are non-static.

So, am I doing something wrong, or is this a limitation imposed by Scala?

Edit -- Here is the relevant code:

package test

import rsca.gs.model.Player

object Test {
     def handle(p:Player): Unit = {
         p.getActionSender().sendTeleBubble(0, 0, false);
     }
}

Player class:

package rsca.gs.model;        
    // imports        
public final class Player extends Mob {
        //  Implemented methods (not going to post them, as there are quite a few)    
        // Relevant code
        private MiscPacketBuilder actionSender;
        public MiscPacketBuilder getActionSender() {
        return actionSender;
    }
}

Error: value getActionSender is not a member of rsca.gs.model.Player

Upvotes: 3

Views: 238

Answers (3)

thoredge
thoredge

Reputation: 12601

Is it possible for you to run a test against the class just to see if you got the right one?

p.getClass.getMethods

... and if possible (may run into NPE) in order to find the source:

p.getClass.getProtectionDomain.getCodeSource.getLocation.getPath

Upvotes: 1

Landei
Landei

Reputation: 54584

I never encountered such problems, and you probably checked your configuration and everything else twice, so I would guess this is some Eclipse related build issue. You should try to build from the command line in order to see whether Scala or Eclipse is the problem.

Upvotes: 2

Daniel C. Sobral
Daniel C. Sobral

Reputation: 297195

When compiling the Scala class, do something like this:

scalac *.scala *.java

This way, Scala will look a the Java code to see what is available. If, however, the Java code is already compiled and provided as a jar file, just add it to the classpath used when compiling the Scala code.

Upvotes: 0

Related Questions