Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous imports in Scala

Tags:

import

scala

I'm writing a small simulation program in Scala. It is actor-based so I've created a file messages.scala that contains all of the messages that are valid in the system.

Outside of this, I have a management component, management.scala and a file that defines the nodes and links classes nodes.scala. Management and node files both import sim.messages._ and then management does import sim.nodes._ as it needs to be able to instantiate things from that file.

The problem comes with one message type Tick that is used by both management.scala and nodes.scala. Upon compiling the management component, I get:

error: reference to Tick is ambiguous;
it is imported twice in the same scope by
import sim.nodes._
and import sim.messages._

I tried removing the import of messages in the management component since they were apparently already imported in to this scope but then they couldn't find them anymore. Ideas?

like image 302
Alex Avatar asked Mar 02 '13 15:03

Alex


1 Answers

Try

import sim.nodes._
import sim.nodes.{ Tick => NodesTick }

and/or

import sim.messages._
import sim.messages.{ Tick => MessagesTick }

Of course, you will have to rename the references to Tick with the right one.

like image 58
pedrofurla Avatar answered Oct 17 '22 02:10

pedrofurla