Questions tagged «scala-2.10»

1
Scala:什么是TypeTag?如何使用?
我对TypeTag的了解仅是它们以某种方式取代了Manifests。互联网上的信息稀缺,无法使我对这个主题有很好的了解。 因此,如果有人共享指向TypeTag上一些有用材料的链接(包括示例和流行的用例),我将感到非常高兴。也欢迎提供详细的答案和解释。

1
从宏获取带有匿名类方法的结构类型
假设我们要编写一个宏,该宏使用一些类型成员或方法定义一个匿名类,然后使用这些方法创建该类的实例,该实例被静态类型化为结构类型,依此类推。在2.10中的宏系统中是可行的。 0,并且类型成员部分非常简单: object MacroExample extends ReflectionUtils { import scala.language.experimental.macros import scala.reflect.macros.Context def foo(name: String): Any = macro foo_impl def foo_impl(c: Context)(name: c.Expr[String]) = { import c.universe._ val Literal(Constant(lit: String)) = name.tree val anon = newTypeName(c.fresh) c.Expr(Block( ClassDef( Modifiers(Flag.FINAL), anon, Nil, Template( Nil, emptyValDef, List( constructor(c.universe), TypeDef(Modifiers(), newTypeName(lit), Nil, TypeTree(typeOf[Int])) ) …

1
Scala通用方法-T没有可用的ClassTag
我对Scala比较陌生,正在尝试定义通用对象方法。但是,当我在方法中引用参数化类型时,将得到“ T没有可用的ClassTag”。这是一个说明问题的人为示例。 scala> def foo[T](count: Int, value: T): Array[T] = Array.fill[T](count)(value) <console>:7: error: No ClassTag available for T def foo[T](count: Int, value: T): Array[T] = Array.fill[T](count)(value) ^ 在此先感谢您的帮助,以帮助您理解此处的错误以及如何使此示例示例起作用。

1
scala.concurrent.blocking的用例
我遇到了该scala.concurrent.blocking方法,根据Scala文档,这是... 用于指定一段可能被阻塞的代码,从而允许当前的BlockContext调整运行时的行为。正确标记阻止代码可以提高性能或避免死锁。 我有些疑惑: 产生新线程的因素是什么? 这仅适用于scala.concurrent.ExecutionContext.Implicits.global执行上下文还是用户创建的执行上下文? 如果我用blocking {...包装任何可执行文件,该}怎么办? 我们应该使用此构造的任何实际用例。
73 scala  scala-2.10 

1
记录Scala 2.10宏[关闭]
已关闭。这个问题是基于观点的。它当前不接受答案。 想改善这个问题吗?更新问题,以便通过编辑此帖子以事实和引用的形式回答。 2年前关闭。 改善这个问题 我将从一个例子开始。List.fill在Scala 2.10中,这相当于for元组作为宏: import scala.language.experimental.macros import scala.reflect.macros.Context object TupleExample { def fill[A](arity: Int)(a: A): Product = macro fill_impl[A] def fill_impl[A](c: Context)(arity: c.Expr[Int])(a: c.Expr[A]) = { import c.universe._ arity.tree match { case Literal(Constant(n: Int)) if n < 23 => c.Expr( Apply( Select(Ident("Tuple" + n.toString), "apply"), List.fill(n)(a.tree) ) ) …

5
Scala-Seq的大小和长度有什么区别?
Seq的大小和长度有什么区别?什么时候使用,什么时候使用? scala> var a :Seq[String] = Seq("one", "two") a: Seq[String] = List(one, two) scala> a.size res6: Int = 2 scala> a.length res7: Int = 2 一样的? 谢谢
70 scala  scala-2.10  seq 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.