Scala 应用程序中永久隐藏的警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4971399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 02:48:10  来源:igfitidea点击:

permanently hidden warning in scala application

scala

提问by trajectory

I get the following warning whenever I start my Scala application:

每当我启动 Scala 应用程序时,都会收到以下警告:

WARN - imported `SVNProperties' is permanently hidden by definition of object SVNProperties in package core, at line 4 of app/core/SVNResource.scala

警告 - 导入的“SVNProperties”根据包核心中对象 SVNProperties 的定义永久隐藏,位于 app/core/SVNResource.scala 的第 4 行

What could this mean?

这意味着什么?

采纳答案by Rex Kerr

You probably have code that looks something like this:

您可能有如下所示的代码:

object Hidden {
  import scala.collection.immutable
  object immutable { def x = 7 }
}

except in a less obvious way. You're importing something--in my example, the package immutable--and then you go and define something else with the same name that prevents you from using what you imported.

除了不太明显的方式。你正在导入一些东西——在我的例子中,包immutable——然后你去定义其他具有相同名称的东西,以防止你使用你导入的东西。

In particular, it looks like you tried to import SVNPropertiesinto SVNResource.scala, except that SVNResource.scaladefines its own SVNPropertieswhich hides the import.

特别是,看起来您试图导入SVNPropertiesSVNResource.scala,除了SVNResource.scala定义自己的SVNProperties隐藏导入。

回答by astasiak

I encountered this warning after moving some classes from one package to another. I guess there was some conflict between the new location and binaries from the old location. In my case this helped:

在将一些类从一个包移动到另一个包后,我遇到了这个警告。我猜新位置和旧位置的二进制文件之间存在一些冲突。就我而言,这有帮助:

sbt clean

回答by Nikhil Kumar K

I got this warning when my class was importing classes in the same package.

当我的班级在同一个包中导入类时,我收到了这个警告。

Once I removed the unnecessary import, the warnings were removed.

一旦我删除了不必要的导入,警告就被删除了。

回答by Aphex

This happened to me after moving a class from one package to another, like in astasiak's case. I ran sbt cleanwith no luck. For the life of me, I couldn't find the class in the old location.

这发生在我将一个班级从一个包转移到另一个包后,就像 astasiak 的情况一样。我跑sbt clean了没有运气。对于我的生活,我无法在旧位置找到课程。

However, I had other errors preventing me from building. When I fixed those, this error disappeared. My guess is that until you can build cleanly, sbtstill thinks you have the class is in the old package, and includes this error with any other build errors that are preventing you from building.

但是,我还有其他错误阻止我进行构建。当我修复这些时,此错误消失了。我的猜测是,在您可以干净地构建之前,sbt仍然认为您拥有该类在旧包中,并将此错误与阻止您构建的任何其他构建错误一起包含在内。

My advice? Check for other compilation errors and fix those-- you might be erroneously getting this error due to sbthaving an outdated view of your package structure since its last successful build.

我的建议?检查其他编译错误并修复这些错误 - 由于sbt自上次成功构建以来您的包结构视图已过时,您可能会错误地收到此错误。

回答by user1485864

Just to further expand on a comment posted by Nick, as this was the case for me:

只是为了进一步扩展尼克发表的评论,因为我就是这种情况:

Another common cause is that SVNProperties is in the same package and so is already in scope. Trying to import it explicitly results in this warning.

另一个常见原因是 SVNProperties 在同一个包中,因此已经在范围内。尝试显式导入它会导致此警告。

More concretely, you may have:

更具体地说,您可能有:

package app.core

// No need to import the following - it is already visible as 
// you are in the same package
import app.core.SVNProperties

object SVNResource {

Use instead:

改用:

package app.core

object SVNResource {

(Opinion) As a matter of coding style you may want to camel case your variables differently like for eg. SvnProperties, SvnResource. It reads easier for most people, see also this question.

意见)作为编码风格的问题,您可能希望以不同的方式对变量进行区分,例如。SvnProperties, SvnResource. 对于大多数人来说,它读起来更容易,另见这个问题

回答by esinik

If you are using Scala Eclipse IDE you can do :

如果您使用的是 Scala Eclipse IDE,您可以执行以下操作:

Project > Clean...

项目 > 清洁...

After that all the warning will be removed.

之后,所有警告都将被删除。

回答by Chalikov

Also, make sure the name of the package you import =/= object name.

另外,请确保您导入的包的名称 =/= 对象名称。

回答by saurav.varma

I had a main class with name Serverand I was creating a jetty server in the main class in the following way.

我有一个名为Server的主类,我正在以下列方式在主类中创建一个码头服务器。

 import org.eclipse.jetty.server.Server

 var server:Server=new Server()

I got the below warn on running sbt run

我在运行sbt run 时收到以下警告

 > [warn] /home/xxx/xxx/xxx/src/main/scala/com/xxx/xxx/main/Server.scala:3:

> imported `Server' is permanently hidden by definition of object Server in package main
    [warn] import org.eclipse.jetty.server.Server
    [warn]                                 ^
    [warn] one warning found

I renamed my main class and the warning disappeared.

我重命名了我的主类,警告消失了。