小编Dzh*_*zhu的帖子

scala匹配案例使用:: for lists

鉴于此模式匹配:

List(1,2,3) match {
  case head :: tail => println(">>> head=" + head)
}
Run Code Online (Sandbox Code Playgroud)

我假设'::'是在scala.collection.immutable中找到的case类,但是如何允许'::'以该形式写入(中缀表示法)? - 有一个特定的规则允许吗?

谢谢

scala

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

不可变集合上的+ =运算符

当我这样做时:

var airlines = Set("Qantas", "JetStar", "Air NZ")
airlines += "Virgin"
Run Code Online (Sandbox Code Playgroud)

航空公司是一个不可改变的集合.

+= 没有在不可变的Set trait上定义.

所以是+=Scala中的一个内置的操作?我的意思是scala如何知道用新的航空公司重新分配航空公司set("Qantas", "JetStar", "Air NZ", "Virgin")

scala

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

解释Mongostat和Mongotop输出

我正在使用mongostat和对mongodb进行一些分析mongotop

我跑mongotop:

$> mongotop 30
Run Code Online (Sandbox Code Playgroud)

和mongostat简单地说:

$> mongostat
Run Code Online (Sandbox Code Playgroud)

产出是:

Mongotop:

                    ns       total        read       write      2012-11-23T01:32:37
           sapi.Socket      1222ms      1222ms         0ms
       sapi.ChargeSpot       999ms       999ms         0ms
Run Code Online (Sandbox Code Playgroud)

Mongostat:

insert  query update delete getmore command flushes mapped  vsize    res faults          locked db idx miss %     qr|qw   ar|aw  netIn netOut  conn     set repl       time 
     0   5351      0      0       0       1       0   608m  3.67g    64m      0          sapi:0.0%          0       0|0     1|0   569k     1m    63 capi-rs  PRI   12:32:41 
     0   4189      0      0       0       1       0   608m …
Run Code Online (Sandbox Code Playgroud)

profiling mongodb

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

Java EE 6 - 嵌入式容器EJB测试

这个问题是关于Java EE 6,使用glassfish v3 embedded-all.

我有一个单元测试,使用EJBContainer来测试我的无状态EJB.问题是我在使用JNDI查找EJB(远程)时遇到问题:

setup() {

  ctx = EJBContainer.createEJBContainer().getContext();

}

...

test() {

BookService bookService = (BookService)ctx.lookup("java:global/BookServiceEJB!com.something.service.BookService");

...

}

@Stateless
public class BookServiceEJB implements BookService {
...
}

@Remote
public interface BookService {
...
}
Run Code Online (Sandbox Code Playgroud)

给出例外:

javax.naming.NamingException: Lookup failed for 'java:global/BookServiceEJB!com.something.service.BookService' in SerialContext  [Root exception is javax.naming.NameNotFoundException: BookServiceEJB!com.something.service.BookService not found]

...

caused by: javax.naming.NameNotFoundException: BookServiceEJB!com.something.service.BookService not found
Run Code Online (Sandbox Code Playgroud)

我尝试了几个JNDI资源路径:

例如

java:global/BookServiceEJB

java:global/BookService
Run Code Online (Sandbox Code Playgroud)

甚至:

java:global/BookShelf-1.0-SNAPSHOT/BookServiceEJB
Run Code Online (Sandbox Code Playgroud)

等等...

没有用

没有配置任何xml部署文件,只有persistence.xmlMETA-INF.

测试使用maven surefire: …

jndi java-ee glassfish-embedded java-ee-6 glassfish-3

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

scala中的超类构造函数

Scala对超类构造函数参数的处理令我感到困惑......

使用此代码:

class ArrayElement(val contents: Array[String]) {
   ...
}

class LineElement(s: String) extends ArrayElement(Array(s)) {
  ...
}
Run Code Online (Sandbox Code Playgroud)

LineElement被声明为扩展ArrayElement,我觉得Array(s)参数in ArrayElement(Array(s))正在创建一个Array实例 - 运行时??? 这是scala的合成糖还是还有其他东西在这里?

scala scala-2.8

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