Scala无法访问Java方法 [英] Scala trouble accessing Java methods

查看:247
本文介绍了Scala无法访问Java方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一些用Java写的东西,我想在Scala中扩展它.我遇到的问题是Scala没有看到我需要的方法.

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.

设置方法如下: 播放器扩展Mob,而Mob扩展实体.

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

我需要访问Player中未在Mob或Entity中定义的方法,但是即使Java确实存在,Scala也认为它不存在.

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.

它可以很好地看到由Mob和Entity定义的方法.而且,我正在谈论的所有方法都是非静态的.

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

那么,我是在做错什么,还是Scala施加的限制?

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);
     }
}

播放器类:

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;
    }
}

错误: 值getActionSender不是rsca.gs.model.Player的成员

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

推荐答案

我从未遇到过此类问题,并且您可能两次检查了配置和其他所有内容,所以我想这是与Eclipse相关的构建问题.您应该尝试从命令行进行构建,以查看问题是Scala还是Eclipse.

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.

这篇关于Scala无法访问Java方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆