简体   繁体   English

Intellij无法识别Scala List运算符

[英]Intellij does not recognize Scala List operator

Here is the intellij warning : 这是intellij警告:

在此输入图像描述

When overing "::" Intellij display this message : Cannot resolve symbol :: 当覆盖“::”时,Intellij显示以下消息:无法解析符号::

I have scala + sbt plugins correctly installed. 我正确安装了scala + sbt插件。

How can i fix this error ? 我该如何解决这个错误?

Your code is incorrect : :: is a method on List , not on Integer . 您的代码不正确::List上的方法,而不是Integer上的方法。 Your last element must be an instance of List . 您的最后一个元素必须是List的实例。

Either of those will work : 这些都可以工作:

val otherList = 3::2::List(3)

or 要么

val otherList = 3::2::3::Nil

Note that :: is called on List and not the Integer because it is right-associative. 请注意::List上调用,而不是Integer因为它是右关联的。

From the Scala Specification ( Infix Operations , 6.12.3) : 来自Scala规范Infix Operations ,6.12.3):

The associativity of an operator is determined by the operator's last character. 操作员的关联性由操作员的最后一个字符决定。 Operators ending in a colon ':' are right-associative. 以冒号':'结尾的运算符是右关联的。 All other operators are left-associative. 所有其他运算符都是左关联的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM