小编she*_*lic的帖子

为什么选项不可穿越?

Option不存在是否合理Traversable

在Scala 2.9中,Seq(Set(1,3,2),Seq(4),Option(5)).flatten不编译并且只是让它实现Traversable对我合理的特征接缝.如果不是这样,那么我必须看到一些不允许的东西.它是什么?

PS:在尝试理解的过程中,我实现了很多可编译的东西,比如:

scala> Seq(Set(1,3,2),Seq(4),Map("one"->1, 2->"two")).flatten
res1: Seq[Any] = List(1, 3, 2, 4, (one,1), (2,two))
Run Code Online (Sandbox Code Playgroud)

PS2:我知道我可以写:Seq(Set(1,3,2),Seq(4),Option(5).toSeq).flatten或其他丑陋的东西.

PS3:在上个月有接缝工作,Option看起来更像是Traversable没有实现它:提交,另一个提交

collections scala

15
推荐指数
1
解决办法
1933
查看次数

显示编译器警告而不编辑pom.xml

我想在使用Maven编译时始终显示编译器警告和弃用.我知道如何通过编辑来实现pom.xml,但我希望这种行为默认只为我自己(所以我无法编辑pom.xml).

我试过了:

mvn -Dmaven.compiler.showWarnings=true -Dmaven.compiler.showDeprecation=true clean compile
Run Code Online (Sandbox Code Playgroud)

但这并没有显示任何警告(如果我修改pom.xml它们以显示它们,它们就在那里).

两个表达式(maven.compiler.showWarningsmaven.compiler.showDeprecation)都存在.

我错过了什么?

compiler-warnings maven

6
推荐指数
1
解决办法
2933
查看次数

如何在编译时进行类型检查?

TraversableOnce,有一种sum方法只有在包含的类型是Numeric(否则它不会编译)时才可用.我想知道这是否可用于其他情况(以避免运行时检查).

特别的情况下,我们有两个特征A和B.我们希望有一个方法f只能如果对象继承使用两个 A和B.但是,如果它只是扩展不是其中之一.我不想再做一个trait AB extends A with B.我只是希望无法使用,f如果不是两个特征都被继承.

package com.example

trait Base
trait Foo extends Base {
  def g = println("foo bar " + toString)
}
trait Bar extends Base {
  /* If this is both Foo and Bar, I can do more */
  def f = {
    if (!this.isInstanceOf[Foo]) error("this is not an instance of Foo")
    this.asInstanceOf[Foo].g
  }
}
object Test {
  def main(args: Array[String]): Unit …
Run Code Online (Sandbox Code Playgroud)

types scala traits

4
推荐指数
1
解决办法
536
查看次数

在Ubuntu 12.04上安装Scala 2.10.2

我在尝试为Scala版本2.10.2安装.deb文件时遇到问题.

我收到以下错误:

(Reading database ... 
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... …
Run Code Online (Sandbox Code Playgroud)

ubuntu scala dpkg

1
推荐指数
1
解决办法
5227
查看次数

标签 统计

scala ×3

collections ×1

compiler-warnings ×1

dpkg ×1

maven ×1

traits ×1

types ×1

ubuntu ×1