开发者

Problem when importing package in scala

开发者 https://www.devze.com 2023-02-16 13:20 出处:网络
Suppose I have such packages: package test package test.views package test.others package views Now in a scala file,开发者_JS百科 I want to import test._ and views._(not test.views._), so I write:

Suppose I have such packages:

package test
package test.views
package test.others
package views

Now in a scala file,开发者_JS百科 I want to import test._ and views._(not test.views._), so I write:

import test._
import views._

But when I use some classes under views._, it reports type xxx not found, unless I change views package to another name.

What should I do now?


You can switch package import order (theoretically it should work):

import views._
import test._

Or you can be more precise in views import:

import _root_.views._


Here's yet another way (though using _root_ is the surest way to go):

import test.{views => testviews, _}
import views._
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号